當前位置:首頁 » 圖片知識 » 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());

這樣就可以把圖片放在最下面了,效果圖: