Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get JButton default background color?

I use this myButton.setBackground(myColor) to change the JButton background color to my color, how to find it's original default background color so I can change it back? I know I can save its default background color before I change and use that, but I wonder if Java stores it somewhere so that maybe I can call something like: myButton.getClass.getDefaultBackground() to get it back ?

like image 616
Frank Avatar asked Aug 31 '09 17:08

Frank


3 Answers

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

how about this... it will get the default color of button

like image 90
Shiburagi Avatar answered Nov 17 '22 16:11

Shiburagi


myButton.setBackground(null)

changes it back to the default color.

like image 38
MoRe Avatar answered Nov 17 '22 16:11

MoRe


This might help:

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.
like image 3
mschmidt42 Avatar answered Nov 17 '22 15:11

mschmidt42