Java’s Swing GTK LaF nice and pretty on Ubuntu

In Ubuntu Java apps which use Swing’s GTK Look and Feel (LaF) do not appear as native applications.

The menus does not have borders and do not appear as app menus on the top of the screen nor provide HUD support. The fonts on buttons and dialog boxes are thinner and do not match to the native look and feel.

This how-to describes step by step how you improve the GTK LaF of Java’s Swing apps.

For Linux Mint (Cinnamon, XFCE) refer my posting Display Java’s Swing menus correctly in GTK LaF for details.

Global Menu and HUD support

For the global menu and HUD support you need to install the package “Ayatana”. This solves the border problem as a positive side-effect. Because it is not in Ubuntu’s repositories you have to get it via PPA. You have to type in the terminal:

sudo add-apt-repository ppa:danjaredg/jayatana
sudo apt-get update
sudo apt-get install jayatana

Once installed, log out and log back in. If you want to perform the following steps too, you just need to log out and in at the end of the whole process.

Better Font Rendering

To improve the appearance of fonts in Java apps install the package  “Infinality” from the following PPA first:

sudo add-apt-repository ppa:no1wantdthisname/ppa
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install fontconfig-infinality

After install a patch for “OpenJDK” and install/reinstall Java:

sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
sudo apt-get update

OpenJDK7 (e.g. Ubuntu 14.04 LTS):

sudo apt-get install openjdk-7-jdk

OpenJDK8 (e.g. Ubuntu 15.04 or higher):

sudo apt-get install openjdk-8-jdk

Once installed, log out and log back in at the latest.

The following screenshot shows the Java-IDE “Netbeans” after applying this how-to:

netbeans_ubuntu-gtk

How to revert the changes

To revert the changes made above use the following commands:

sudo apt-get --purge remove jayatana libjayatana libjayatanaag libjayatana-java libjayatanaag-java
sudo apt-get purge fontconfig-infinality
sudo apt-get install ppa-purge
sudo ppa-purge ppa:no1wantdthisname/ppa
sudo ppa-purge ppa:no1wantdthisname/openjdk-fontfix

Finally reinstall Java (OpenJDK7 oder OpenJDK8).

sudo apt-get remove openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
sudo apt-get install openjdk-7-jre-headless openjdk-7-jre openjdk-7-jdk

or

sudo apt-get remove openjdk-8-jdk openjdk-8-jre openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre-headless openjdk-8-jre openjdk-8-jdk

Once finished, log out and log back.

Related Links

 

3 comments

Leave a Reply

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