这里我就放上改写的代码吧,不作多的解释,推荐一个好的博文this
http://www.javashuo.com/article/p-womajldp-gs.htmlspa
1 public void ini_background() { 2 // 背景图片 3 ImageIcon background = new ImageIcon( 4 this.getClass().getResource("/img/登陆背景.png")); 5 // 把背景图片显示在一个标签里面 6 JLabel label = new JLabel(background); 7 // 设置标签大小 8 label.setBounds(0, 0, 440, 335); 9 // 把内容窗格转化为JPanel,不然不能用方法setOpaque()来使内容窗格透明 10 JPanel imagePanel = (JPanel) this.getContentPane(); 11 imagePanel.setOpaque(false); 12 this.getLayeredPane().setLayout(null); 13 // 把背景图片添加到分层窗格的最底层做为背景 14 this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE)); 15 }