Yen
Yen

Reputation: 25

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?

Upvotes: 0

Views: 68

Answers (1)

PrR3
PrR3

Reputation: 1246

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

Upvotes: 1

Related Questions