设置JFrame背景图片

这里我就放上改写的代码吧,不做多的解释,推荐一个好的博文

https://blog.csdn.net/jdsjlzx/article/details/16831815

 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 }

猜你喜欢

转载自www.cnblogs.com/Lu-Yuyang/p/9939660.html
今日推荐