Make Java use the GTK look & feel on Linux

11 01 2009

Java programs are more and more common these days. And why shouldn’t they be? It’s an easy to use language, it’s cross-platform (or it is supposed to be cross-platform) and has a huge standard class library. Apart from the fact that you need a VM to run them, which slows them down a little (but this is generally not noticable), and ties them to a propretairy vendor, there’s no real problem with Java programs…

No real problem? Well, there is one big problem: Java programs on Linux look terrible. The default look and feel, “Metal”, is very ugly. But it’s at least cross platform ;) . Well, since 1.6.0, (Sun’s) Java has support for a GTK Look & Feel — why no Qt? See my article about the GPL — built into the VM. But it’s not enabled by default. I’ve tried running a program with Metal and with GTK Look & Feel, and man, that’s a huge difference! This is how to enable GTK Look & Feel for all programs.

First, you’ll have to locate the directory your JVM is residing in. Unless your distribution did some real weird things, it’s usually either /usr/lib/jvm/<version> or /usr/java/[<version>] . Wherever it might be located, i’ll use /usr/lib/jvm/jre-1.6.0_10/ for the examples.

Locate the file named /usr/lib/jvm/jre-1.6.0_10/lib/swing.properties. If it doesn’t exist, create it.

Put the following inside the file:

swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

Save, quit, try running an application and see if it worked :)

Screenshots:

NetBeans with Metal L&F

NetBeans with Metal L&F

NetBeans with GTK L&F

NetBeans with GTK L&F


Actions

Information

Leave a comment

You must be logged in to post a comment.