简体   繁体   中英

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

I'm trying to make my JPanel change opacity when focused.

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?

This can be solved by implementing a 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.

detailed description could be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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