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.
I know the response is belated, but if anyone sees this question on google (like I did) then I find that this solution is better than nothing:
if (UIManager.getLookAndFeel().getClass().getName().equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"))
aPopupMenu.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.gray));
It doesn't seem to work for menus added to popup menus (even if you call the function on them), but it does show the border on the primary menu.
There are incompatible rc-files.
Unfortunately the http://www.ailis.de/~k/ blog is closed.
Ubuntu/Gnome Shell: e.g. /usr/share/themes/Adwaita/gtk-2.0/gtkrc
style "menu" {
xthickness = 1
ythickness = 1 ...
}
... style "separator_menu_item" {
xthickness = 1
ythickness = 1
... }
Update 11/30/2015: For Ubuntu/Unity refer http://blog.hani-ibrahim.de/en/ubuntus-swing-gtk-laf.html => Global menu, native fonts.
On Linux Mint there are the menus.rc
files in the Mint-themes in /usr/share/themes/[mint-theme]/gtk-2.0/style
In section style “menu” change:
xthickness = 0
ythickness = 0
text[ACTIVE] = @base_color
to:
xthickness = 1
ythickness = 1
text[ACTIVE] = @fg_color
In section style “menu-item-separator” change the entry:
ythickness = 0
to:
ythickness = 1
I wrote a bash-script for Mint which does the job automatically. It fixes all 3 problems:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With