How to get back the original look and feel color of a button after changing its color? [closed]

StackOverflow https://stackoverflow.com/questions/15821549

سؤال

I changed the color of my button. Now I want its original look and feel back. I want to change the color once to a color that i like. After that, I want the button to get its original look back.

How do I do that ?

Here is the code to change color -

JButton but = JButton("Press now to up vote"); // :)
but.setBackground(Color.orange); 
//code to remove this color and get the original look back ???
هل كانت مفيدة؟

المحلول

Color oldColor = myButton.getBackground();
myButton.setBackground(Color.RED);
// ... do stuff
myButton.setBackground(oldColor);

نصائح أخرى

I want the button to get its original look back.

  • this code should be only button.setBackground(null);

Is there a way to find out the name/code of the old color

  • by default Colors has not a names, only safe Colors(blue, red, orange ....)

  • old color not JButton has arrays of Colors

  • UIManager returns javax.swing.plaf.ColorUIResource[r=xxx, g=xxx, b=xx], contains arrays of Colors and Insets

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top