Customizing colors for the MotifLookAndFeel
Hello,
I am new to look and feels other than the default one.
I am supposed to provide an application with a a Motif UI with a specific color scheme (colors of text, backgrounds, menus, etc.).
Is there some API to configure Sun's MotifLookAndFeel colors?
Other than that, here are the options I can list:
1) System config file:
I am not exactly good at Motif configuration but I guess Sun's MotifL&F bundled in the JRE will try to get the default colors from some motif.rsc or whatever it's called, in the user's home.
However I don't want to alter this file as only my application should have custom colors, I don't want toi impact other Motif apps for the same user/host.
2) UIDefaults:
As I understand it, class UIDefaults represents a table provided by the installed LookAndFeel class, which can be changed afterwards, through the UIMAnager class. However, that doesn't force the L&F to take the changes into account. Indeed the MotifL&F doesn't seem to take any of those changes into account.
3) Custom MotifL&F subclass
I assume I could also subclass com.sun.java.swing.plaf.motif.MotifLookAndFeel and override getUIDefaults(), but that seems awkward just to change a handful of colors and no behavior.
I'm not even sure MotifLookAndFeel fetches the color values from UIDefaults once it has initialized it...
Any other suggestion?
[1446 byte] By [
jdupreza] at [2007-11-26 15:08:32]

# 2
Thanks but I don't feel at ease with this solution (extending a class to change its configuration, whereas the base class can be configured through a public API).
However your suggestion to peek a the code truly helped me: the names of the keys I was using in UIDefaults were simply wrong! :o)
Actually I got a list of keys from this page: http://java.sun.com/products/jfc/tsc/articles/lookandfeel_reference/index.html , but in the source for the sun.java.swing.plaf.motif classes you can see the "correct" keys (e.g. MotifMenuItemUI extends BasicMenuItemUI which uses "MenuItem.background" and not "menu").
The other good news is that the keys can be set beforehand (before actually setting the LaF): although the LaF provides its own UIDefaults, the UIManager stores them in a MultiUIDefaults, and the defaults installed via UIManager seem to take precedence...
That was more convenient in my case.
For reference here is an extract of my code:
UIManager.put("menu", new ColorUIResource(0,250,20)); // helpless, wrong key
UIManager.put("menutext", new Color(200,0,200)); // helpless
UIManager.put("MenuItem.background", new Color(255,50,20)); // taken into account
UIManager.put("Panel.background", new Color(166,255,166)); // taken into account
...
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
Just for convenience, does anyone know a good Web resource for the keys used by the various LookAndFeel classes, or at least the BasicLookAndFeel? Other than looking at the code for all XxxUI classes, of course :o)