简体   繁体   English

聚焦时如何更改JPanel的不透明度?

[英]How can I change a JPanel's opacity when focused?

I'm trying to make my JPanel change opacity when focused. 我正在尝试使我的JPanel更改焦点时的不透明度。

Right now, I use this; 现在,我用这个;

Main main = new Main();
Main.setOpacity(0.75f);

This works fine but is there any way I can make the opacity go down when the JPanel is not focused and then back up to .75 when it regains focus? 这可以正常工作,但是有什么办法可以使JPanel未聚焦时降低不透明度,然后在重新获得聚焦时使其回到0.75?

This can be solved by implementing a FocusListener . 这可以通过实现FocusListener来解决。

the method public void focusGained(FocusEvent e) sets the opacity to 0.75 and the method public void focusLost(FocusEvent e) decreases the value according to your needs. 方法public void focusGained(FocusEvent e)将不透明度设置为0.75,方法public void focusLost(FocusEvent e)会根据您的需要减小该值。

detailed description could be found here 详细说明可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM