class MyBkFrame extends JFrame{ MyBkFrame( String name ){ JPanel pan = new JPanel(new BorderLayout()); ImageIcon ii = new ImageIcon(name);//加载图片 JLabel lab = new JLabel(ii);//图片放到Label内 lab.setBounds(0, 0,ii.getIconWidth(), ii.getIconHeight());//设置Label的大小正好是图片大小 this.getLayeredPane().setLayout(null);// this.setTitle("测试Java的背景图片设置"); this.getLayeredPane().add(lab, new Integer(Integer.MIN_VALUE));//把Label(内有图片)放到工作区的下层,做背景图片 this.setContentPane(pan);//设置装有操作组件的Panel为ContentPnel pan.setOpaque(false);//设置Pan为透明 int w = Toolkit.getDefaultToolkit().getScreenSize().width; int h = Toolkit.getDefaultToolkit().getScreenSize().height; setBounds(0, 0, w, h); setVisible(true); this.setDefaultCloseOperation(EXIT_ON_CLOSE); } }