Mueretee
Mueretee

Reputation: 550

Change color to a JPanel and return to original

I need to change the color to my jPanel, that's easy, but then you can return to the original color.
The application can change color at any time, so can not be a static color, must vary according to the background color of the application.

Im trying this:

Color defaultColor;  
defaultColor = m_jButtons.getBackground();  
m_jButtons.setBackground(Color.red);  
//And then  
m_jButtons.setBackground(Color.defaultColor);

m_jButtons.setBackground(Color.defaultColor); this wont work (logically).
Anyone knows any method to do that?

Upvotes: 1

Views: 140

Answers (1)

Gelunox
Gelunox

Reputation: 792

It doesn't work because the color you definded is not part of the java.awt.Color class

You should do

m_jButtons.setBackground(defaultColor);

assuming the variable is accessible from where you want to set it.

Upvotes: 2

Related Questions