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