知识预备:
jframe的组成:
jrootpane中包含glasspane和layeredpane两个面板。而layeredpane面板包含contentpane(内容面板)和jmenubar(菜单面板)
在jframe上添加组件,往往是添加在contentpane中,但是在contentpane的下面还有两层面板,那就是layeredpane和jrootpane
我的实现:
//将背景图绘在JFrame的倒数第二底层的Layeredpane上
JLabel picLabel = new JLabel();
picLabel.setIcon(new ImageIcon( "img//主界面.jpg"));
this.getLayeredPane().add(picLabel, new Integer(Integer.MIN_VALUE));
picLabel.setBounds(0,0,1024,768);
//再在JFrame的最上层contentpane上添加按钮并且设置contentpane为透明。
JPanel content = new JPanel();
content=(JPanel)getContentPane();
content.setOpaque(false);
content.add(monthOrWeekPlanBtn);
这样就可以显示背景图片和按钮了。。。。。
欢迎转载,请注明出处:http://writeblog.csdn.net/PostEdit.aspx