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

跟風遠走 提交于 2019-12-27 03:32:54

问题


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 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



来源:https://stackoverflow.com/questions/15821549/how-to-get-back-the-original-look-and-feel-color-of-a-button-after-changing-its

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!