当前位置:首页 » 图片知识 » swing中如何设置图片
扩展阅读
女生和渣男搞笑图片 2023-08-31 22:07:09
嘻嘻长什么样图片 2023-08-31 22:06:10

swing中如何设置图片

发布时间: 2023-03-01 03:03:06

① 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());

这样就可以把图片放在最下面了,效果图: