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.get edPane().setLayout(null);
13     // 把背景图片添加到分层窗格的最底层作为背景
14     this.get edPane().add(label, new Integer(Integer.MIN_VALUE));
15 }

 

收藏 打印