问题
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 ???
回答1:
Color oldColor = myButton.getBackground();
myButton.setBackground(Color.RED);
// ... do stuff
myButton.setBackground(oldColor);
回答2:
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 safeColors(blue, red, orange ....)
old color
not JButton has arrays of ColorsUIManager returns
javax.swing.plaf.ColorUIResource[r=xxx, g=xxx, b=xx]
, contains arrays ofColors
andInsets
来源:https://stackoverflow.com/questions/15821549/how-to-get-back-the-original-look-and-feel-color-of-a-button-after-changing-its