码迷,mamicode.com
首页 > 其他好文 > 详细

设置JFrame背景图片

时间:2018-11-10 16:41:58      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:new   red   pre   bounds   public   details   tco   etc   lse   

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

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背景图片

标签:new   red   pre   bounds   public   details   tco   etc   lse   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!