loadingLab=new JLabel("The name is being saved..");
loadPanel.add(loadingLab);
submitBttn=new JButton("Submit");
submitBttn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Submit Button Clicked!!");
try {
//something is wrong in here as it throws an exception
//what is wrong?
frame.setUndecorated(false);
frame.setOpacity(0.55f);
//when above both lines are commented, the code works fine
//but doesnt have transparency
frame.add(loadPanel,BorderLayout.SOUTH);
frame.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
我想顯示透明JFrame
當「提交」按鈕時,顯示有JLabel
面板... 我一直在使用setOpacity(0.55f)
嘗試,但它拋出異常..我到底做錯了什麼?點擊「提交」按鈕時如何設置半透明jframe?
1)爲了更快地獲得更好的幫助,請發佈[MCVE]或[簡短,獨立,正確的示例](http://www.sscce.org/)。 2)總是複製/粘貼錯誤和異常輸出! –
爲了達到這個目的,框架必須是未修飾的(你做過'frame.setUndecorated(false);')。另外,如果你在actionlistener中使現有的框架不被修飾,你必須在它之前調用'frame.dispose()'(在它之後調用'frame.setVisible(true)') –
@LuxxMiner thanx以獲得建議.... – Programmer007