我使用 myButton.setBackground(myColor)
来改变 JButton
的背景颜色为我的颜色,如何找到它的默认原始背景颜色,以便可以将其还原?我知道我可以在更改之前保存其默认背景颜色并使用它,但我想知道Java是否在某个地方存储了它,这样也许我可以调用像 myButton.getClass.getDefaultBackground()
这样的方法来获取它?
我使用 myButton.setBackground(myColor)
来改变 JButton
的背景颜色为我的颜色,如何找到它的默认原始背景颜色,以便可以将其还原?我知道我可以在更改之前保存其默认背景颜色并使用它,但我想知道Java是否在某个地方存储了它,这样也许我可以调用像 myButton.getClass.getDefaultBackground()
这样的方法来获取它?
btn.setBackground(new JButton().getBackground());
这个代码的意思是设置按钮的背景颜色为默认颜色。
怎么样,这样说清楚了吗?
myButton.setBackground(null)
将其更改回默认颜色。
这可能有所帮助:
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.
button.setBackground(null);
并且
button.setBackground(new JButton().getBackground());
不要尝试从Jframe或其他元素获取背景并将其应用于按钮;如果您已经更改了它,请执行以下操作:
ElementToStyle.setBackground(null);
现在默认的背景颜色存储在颜色变量“jbb”中,您可以将其用作您想要查找/使用的颜色。
Color cbt= jButton6.getBackground();
String color_button=cbt.getRed()+","+cbt.getGreen()+","+cbt.getBlue();