我使用它myButton.setBackground(myColor)
来将JButton
背景颜色更改为我的颜色,如何找到它的原始默认背景颜色以便我可以将其更改回来?我知道我可以在更改和使用它之前保存它的默认背景颜色,但我想知道 Java 是否将它存储在某个地方,以便我可以调用类似的东西:myButton.getClass.getDefaultBackground()
取回它?
问问题
41611 次
7 回答
14
btn.setBackground(new JButton().getBackground());
这个怎么样...它将获得按钮的默认颜色
于 2014-05-09T11:44:34.280 回答
10
myButton.setBackground(null)
将其更改回默认颜色。
于 2012-12-19T17:31:48.843 回答
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.
于 2009-08-31T17:21:07.893 回答
1
它适用于:
button.setBackground(null);
和
button.setBackground(new JButton().getBackground());
(当你创建一个新的JButton时,它的背景颜色被初始化为空颜色)
所以,选择你认为最适合你的项目的那个
于 2019-01-27T09:23:11.203 回答
0
不要尝试从 Jframe 或其他元素中获取背景以将其应用到按钮上;如果您已经更改了它,请执行以下操作:
ElementToStyle.setBackground(null);
于 2014-12-05T03:28:41.093 回答
0
- 制作一个新按钮“db”
- 创建一个新的变量类型颜色“jbb”
- 即 - 颜色 jbb = db.getBackground();
现在默认背景颜色存储在 Color jbb 中,您现在可以将其用作要查找/使用的颜色
于 2015-04-05T02:22:43.407 回答
0
Color cbt= jButton6.getBackground();
String color_button=cbt.getRed()+","+cbt.getGreen()+","+cbt.getBlue();
如果你不会得到 RGB 颜色按钮试试这个代码
于 2018-07-09T16:29:43.760 回答