首页 > 其他 > 详细

设置JFrame背景图片

时间:2018-11-10 16:19:05      阅读:116      评论:0      收藏:0      [点我收藏+]

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

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 }

 

设置JFrame背景图片

原文:https://www.cnblogs.com/Lu-Yuyang/p/9939660.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!