主函數(shù):public static void main(String[] args) { MsClient client=new MsClient("聊天進(jìn)擊~(yú)",410,100,400,500,95,158,160); JFrame.setDefaultLookAndFeelDecorated(true); ? ?client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//設(shè)置點(diǎn)關(guān)閉能夠關(guān)閉面板的命令 client.addBkImage("G:/歡喜/小象與兔子/23.jpg", -10,-10,400,500, 1); client.setLayout(null); ?? client.setVisible(true); } 加的按鈕是這些 public void addAllBtn(){ this.addBtn(container,"選風(fēng)格~", new BackgroundActionListener(container,"G:/歡喜/貓咪/23.jpg"), 150,40); this.addBtn(container,"清新", new BackgroundActionListener(container,"G:/歡喜/貓咪/22.jpg"), 100,330); this.addBtn(container,"極簡(jiǎn)", new BackgroundActionListener(container,"G:/機(jī)智的李承穎/歡喜/清新/09.jpg"), 250,330); }這是我插入背景調(diào)用的函數(shù):public void addBkImage(String path,int x,int y,int w,int h,int index){//"G:/機(jī)智的李承穎/歡喜/貓咪/23.jpg" System.out.println("添加背景"); ImageIcon img = new ImageIcon(path);//這是背景圖片 ?? ? ? JLabel imgLabel = new JLabel(img);//將背景圖放在標(biāo)簽里。 ? ? imgLabel.setBounds(x,y,w,h); ? ? ((JComponent)this.getContentPane()).setOpaque(false); ? ? //將該面板設(shè)置為透明,這樣就能顯示出背景圖片出來(lái)了。 ? ? this.add(imgLabel, index); ? ? //注意這里是關(guān)鍵,將背景標(biāo)簽添加到client的 ?LayeredPane面板里。 ? ? container.setLayout(null);? container.setVisible(true); ? ? }
java中插入背景圖片為什么總是覆蓋掉按鈕啊
Bubblegirl
2016-06-28 11:23:33