Display Java’s Swing menus correctly in Linux Mint’s GTK LaF

Since GTK 3 has been introduced Java Swing applications have a bug in displaying their menus when using the GTK Look and Feel (LaF).

At Linux Mint Cinnamon:

  • No border around dropdown and context menus
  • Wrong font color of activated checkbox and radiobutton menu items (the font has the same color as the background and appears invisible)
  • No menu separators

In the web there are some fixes and workarounds but just one solves the problem on Linux Mint 17 and later completely (see section “Interesting Links” below).

This How-To shows how to fix the problem and offers a bash script to get rid of this problem on Mint 17 and later automatically.

For Ubuntu find a small hint below.

The animated screenshot below shows the problem befor and after the fix.

Menübug in Swings GTK LaF vor und nach der Fehlerbeseitigung

Menu bug in Swing’s GTK LaF befor and after the fix

The problem are entries in the “menus.rc” files of the Mint-themes at /usr/share/themes/[mint-theme]/gtk-2.0/style.

In Ubuntu the configuration is stored in different files (gtkrc), e.g. /usr/share/themes/Adwaita/gtk-2.0/gtkrc. But the entries are pretty similar. Search for the section styles “menu” and look for the entries xthickness und ythickness. Set them to “1“. As an alternative install the  Global Menu/HUD-Support for Java Swing Apps when you use the Unity desktop. See my posting Java’s Swing GTK LaF nice and pretty on Ubuntu for details.

Manuel Fix

Open the path /usr/share/themes/[mint-theme]/gtk-2.0/style your used Mint-theme (e.g. “Mint-X”) as root und edit the file menus.rc.

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

You are done for this theme.

To fix all Mint themes I recommend to use my bash script “swing-menu-corr.sh” below.

The changes have not effected general GTK applications at all!

Automatic Fix

Manually changing all menus.rc to fix the problem is time consuming.  The bash script “swing-menu-corr.sh” does the changes in all files automatically.

Swing-menu-corr.sh-Skript

Swing-menu-corr.sh-script

The script changes only Mint Themes of Linux Mint 17.x! It works well with the Cinnamon and Xfce versions.

Update 2017-01-29: The script corrects Mint-X and Adwaita themes on Mint 17 or later only.  Linux Mint 18’s Mint-Y themes are not supported (now). Refer workaround in my comment. This script works well with Mint’s Cinnamon and Xfce versions.

The script creates backup files of all changed files. You can undo the changes of “swing-menu-corr.sh” with the script “swing-menu-undo.sh” automatically.

Furthermore the script checks if it runs under Linux Mint 17.x. If not, it displays a warning. But do not worry. “Swing-menu-corr.sh” cannot damage your system seriously. The “undo” script can bring back the original files anyway.

Download

logo_mint “swing-menu-corr.sh” at GitHub
Logo Java Java-Testprogram “Menutest.tar.gz

2 comments

  • An alternative to this…. use LXDE

  • Derzeit korrigiert “swing-menu-corr.sh” auch unter Linux Mint 18 alle Mint-X und Adwaita Themen (ohne Warnmeldung). Leider umfasst es (noch) nicht die Mint-Y Themen. Als Workaround verwende im Themen-Dialog unter “Steuerung” bis auf Weiteres die Mint-X Einstellung (siehe Screenshot w.u.). Oder bleibe bei den Mint-X oder Adwaita Themen. Die Mint-Y Themen sind anders aufgebaut und ich weiß nicht ob und wie schnell ich eine Anpassung liefern kann.

    Now “swing-menu-corr.sh” works on Linux Mint 18 without any warning on all Mint-X and Adwaita themes. Unfortunately it does not work on Mint-Y themes. As a workaround use in the Theme dialog at “Controls” the Mint-X setting for now (refer screenshot below) or still use the Mint-X or Adwaita themes. The Mint-Y themes are designed differently to the Mint-X themes. I do not know whether or when I can provide a working solution.

    Mint-Y Workaround

Leave a Reply

Your email address will not be published. Required fields are marked *