如何获得JButton的默认背景颜色?

Fra*_*ank 7 background default colors jbutton

我用这个myButton.setBackground(myColor)来改变JButton背景颜色到我的颜色,如何找到它的原始默认背景颜色,以便我可以改回来?我知道在更改和使用它之前我可以保存它的默认背景颜色,但是我想知道Java是否将它存储在某处,以便我可以调用类似的东西:myButton.getClass.getDefaultBackground()将它取回?

小智 11

btn.setBackground(new JButton().getBackground());

怎么样...它将获得按钮的默认颜色


MoR*_*oRe 8

myButton.setBackground(null)
Run Code Online (Sandbox Code Playgroud)

将其更改回默认颜色.

  • 这会将其更改为空颜色,而不是默认颜色. (3认同)

msc*_*t42 3

这可能有帮助:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/SystemColor.html

Toolkit.getDesktopProperty(java.lang.String)
Toolkit.getDesktopProperty("control");
// control - The color rendered for the background of control panels and control objects, such as pushbuttons.
Run Code Online (Sandbox Code Playgroud)