my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes How to retrieve constant for bg-color of a JPanel? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to retrieve constant for bg-color of a JPanel?" Watch "How to retrieve constant for bg-color of a JPanel?" New topic
Author

How to retrieve constant for bg-color of a JPanel?

Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Defining a central constant referring to the default background color of a JPanel I do the following as a first approach:


Works fine, however, is it really necessary to create a new object in order to retrieve that specific color, or is there any constant defined in the SE-API I can use directly instead?


SCJP, SCJD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

UIManager.getColor("Panel.background") should do the trick.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
that's exactly 100% what I needed!
Thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

You're welcome.
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
Rob, is there a list anywhere presenting all those literals like "Panel.background" ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

There may be lists on the Internet but I don't know of any. You can create such a list yourself though. Unzip the src.zip file in your JDK folder, go to folder javax/swing/plaf/basic and check each file. That's how I found this one.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Rob Camick's UIDefaults.java will give you most, but read the comments for limitations

http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/
Andy Jung
Ranch Hand

Joined: Feb 07, 2010
Posts: 150
... ok, thanks guys again for your great help and hints !
Rob Camicks tool is pretty nice, he also has some precious threads!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retrieve constant for bg-color of a JPanel?
 
Similar Threads
JTextField background color and UIManager
JTable serialization problem
how to use rgb color values to set JPanel background color
JPanel Transparent does not work with setO
How/Where can i find all swing properties keys ?