I have an already written Java Swing app (so no switching UI frameworks) that I would like to look at least decent using the GTKLookAndFeel. I've already accounted for things like font and component size differences across LookAndFeels, but one thing I can't figure out is why my popup menus have no borders at all. It appears they are using Synth borders which don't look GTK native. I would like to be able to support Metal, Windows, and GTK, but these popups look terrible. Is this a bug? What's a nice (non hacky) way to fix this without affecting the other LookAndFeels' borders which look fine?
In my opinion GTK LaF is broken by design. It does not honor the programmers UI settings (font color borders background etc) for seemingly random JCOmponents. This is because it gets its settings from a .gtkrc file, not setXXX(...) calls. I'd stick with Metal for Linux and 'native' for windows.
Response:
The GTK+ look and feel can be customized by way of resource files. Swing's GTK+ look and feel uses the following algorithm to locate the resource files:
- If the system property swing.gtkthemefile exists, parse it and stop, for example: java -Dswing.gtkthemefile=/tmp/customTheme -jar SwingSet2.jar.
- If the file user.home/.gtkrc-2.0 exists, parse it and continue.
- Determine the user selected theme name (THEMENAME) by way of the desktop property gnome.net/ThemeName which is determined using XSETTINGS. If this property is null, use Default as THEMENAME. 1. If the file user.home/.themes/THEMENAME/gtk-2.0/gtkrc exists parse it and stop. 2. If the system property swing.gtkthemedir exists and the file swing.gtkthemedir/THEMENAME/gtk-2.0/gtkrc exists, parse it and stop. 3. If the system property swing.gtkthemedir doesn't exist and the file /usr/share/themes/THEMENAME/gtk-2.0/gtkrc exists, parse it and stop. 4. Lastly if swing.gtkthemedir is defined parse swing.gtkthemedir/THEMENAME/gtk/gtkrc, otherwise parse /usr/share/themes/THEMENAME/gtk/gtkrc.
One way GTK+ can be customized is by way of a theme engine. A handful of engines exist. In 1.4.2, Swing supports theme files for Default, pixmap, and bluecurve engines. We are investigating ways to open up the API to allow for the creation of additional GTK engines. Visit http://www.themes.org for examples.
- http://java.sun.com/j2se/1.4.2/docs/guide/swing/1.4/Post1.4.html
My guess is that java is taking its theme from another rc file OR the current border options aren't supported.