1. 程式人生 > >設定JFrame背景圖片

設定JFrame背景圖片

這裡我就放上改寫的程式碼吧,不做多的解釋,推薦一個好的博文

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 }