① Java swing 窗体如何设置背景图片
background=newImageIcon("images/backImage.png");
backImage=newJLabel(background);
backImage.setBounds(0,0,background.getIconWidth(),
background.getIconHeight());
backPanel=(JPanel)this.getContentPane();
backPanel.setOpaque(false);
this.getLayeredPane().setLayout(null);
this.getLayeredPane().add(backImage,newInteger(Integer.MIN_VALUE));
backPanel.setLayout(newBorderLayout());
这个是我程序里面复制出来的,效果就下面图一样。
② java中的swing设计界面时怎么加上背景图片。而不覆盖什么label等控件
通过以下方式设置下背景就可以了:
background=newImageIcon("images/backImage.png");
backImage=newJLabel(background);
backImage.setBounds(0,0,background.getIconWidth(),
background.getIconHeight());
backPanel=(JPanel)this.getContentPane();
backPanel.setOpaque(false);
this.getLayeredPane().setLayout(null);
this.getLayeredPane().add(backImage,newInteger(Integer.MIN_VALUE));
backPanel.setLayout(newBorderLayout());
这样就可以把图片放在最下面了,效果图: