UIManager Defaults
Posted by Rob Camick on October 9, 2008
The UIManager contains information about the default properties of each Swing component. This information is stored in the UIDefaults class in the form of key/value pairs. Each Look and Feel will have its own set of default properties. The UIManager can be used to make changes to these properties.
At times you may want to know what the default value of a property is for a specific component. You can use code like this to get the default font for a JTextField:
Font font = UIManager.getFont("TextField.font");
Other times you may want to change the default value of a property for a specific component. You can use code like this to change the default font for all JTextFields:
UIManager.put("TextField.font", new FontUIResource( yourFontHere ));
Of course not all properties of a component can be controlled through the UIManager, so the question is – what properties are managed by the UIManager? Well, as mentioned earlier, all the information is contained in the UIDefaults class. The UIManagerDefaults program will simply display this information in a nicely formatted way.
Note that not all Look and Feels (LAF) use the same properties, so this type of solution can be very LAF dependent.
Try The Demo
- Using Java™ Web Start (JRE 6 required)

BoBear2681 said
Also it’s important to keep in mind that the property keys defined in the UIManager can vary from one LookAndFeel to the next. Sun’s “standard” looks – Windows, Metal and Motif – all utilize pretty much the same values (or maybe *all* the same values?). But this isn’t a guarantee.
Nimbus, for example, doesn’t define many of the properties those other looks do, and defines some of its own. This unfortunately makes it difficult to do heavy customization of components through their ComponentUI’s that works across all LookAndFeels. At least, that’s something I’m currently struggling with. :)
Rob Camick said
Good point to remember. I’ve only ever really looked at the Metal and Windows LAF’s. I find that any UI change is not easy when dealing with multiple LAF’s as it needs to be done for every LAF.
So this solution is probably best when dealing with a single LAF.
T.B.M said
Hello camickr!
I was searching for a utility like this. And your program is just perfect!! You have introduced so many features in this simple utility, Thankyou! I really liked the ’sample’ feature.
Though everything is perfect, but there are few problems which I noticed:
1- When the Look and Feel is changed, then all the Window Decorations disappear, Window decorations appear only in Metal LF. This maybe because of this statement:
JFrame.setDefaultLookAndFeelDecorated(true);
Perhaps removing this statement is a good idea because it almost serves no useful purpose ; )
2- When I double click any cell, it allows editing. This causes problems when a ’sample’ cell is double clicked. e.g. if the cell was showing some Icon and I double click it, the icon disappears and text appears which is editable, but when I click outside(even without editing the original text), the Icon or any thing inside the cell disappears. So, I think making the table cells uneditable is a good idea. I don’t know much about swing (don’t know how to make cell uneditable) but you certainly do, so, you can make the suggested changes (if you have spare time).
Thanks once again, and yes, I wanted to ask about property keys like ’swing.boldMetal’. Are there other keys like that? If so, where can I find them? because your utility or UIDefaults (to be more specific) does not list it.
Thanks!
Rob Camick said
Properties contained in the UIManager are not documented anywhere (that I know of), so if a property doesn’t display in my program I don’t know anything about them. The only way to find all references to the properties would be to search the source code for all “UIManager.get” statements.
Mohd Anis Azinan said
Thanks for your good and very helpful work
Saul Mena said
Hello, Rob. Just wanted to tell you this is a great app. Very useful indeed. Thanks a lot!
Rob Camick said
Thanks, this posting is actually the #1 visited posting and #1 code download.
BigDaddyLoveHandles said
Rock on, d00d!
Suggestion: for some components, it would be helpful to tweak values then see the result on a prototype component. JTabbedPane, for example, can have 13 different Color properties, and it’s not obvious how they map to the component. The next step after discovering the keys is to write some code to manually see how the keys map. If your demo allowed for that it would be most excellent.
Rob Camick said
Interesting suggesting. At first glance it seems rather involved so I doubt I’ll get around to it in the near future, but I’ll keep it in the back of my mind.
Janus said
Thank you so, so, so VERY much!
I’ve had a problem with a JTree with a custom rendering component (to add check boxes) and the layout wasn’t pretty using the Windows UI: The rows of the nodes in the table overlapped slightly. Thanks to your program I discovered “Tree.rowHeight”, so after using UIManager.put(“Tree.rowHeight”, 21) the rows were of equal size in the default java UI and Windows UI.
Regards,
Janus
Rob Camick said
Glad it helped find a solution to your problem.
delak said
awesome tool. thank you so much.
Rob Camick said
Thanks for the feedback.