Native look and feel for Swing under Linux

This one is not really an eye-opener, but I use this blog to record and archive stuff I find out at some point, so here’s a post about getting NetBeans Platform Applications use GTK instead of Metal.

Since the Swing Application Framework (SAF) has been deprecated and developing NetBeans Platform Applications (NPA) is the new and better way to do these things, I’ve bought a good book on the subject, and am quite satisfied with the way Java desktop applications are to be developed these days.

However, under Linux, Swing applications default to the ugly Metal widget set:

Metal widget set. Click to zoom.


On the command line and using SAF it is in fact pretty easy to make Swing use the GTK widgets. This way Java applications get a native look and feel under Linux. With NPA however, there is no right place to insert a few lines of code to do this at startup.

To make NetBeans itself use the GTK widgets, I always start the IDE like this:

# netbeans --laf

Since NetBeans is itself an NPA,  I figured the trick would be to specify this option somewhere in the application’s configuration. I googled around a bit and found the answer here. The trick is to add a single line to the file, which can be found inside the Important Files folder within the NPA project. That line is:


And now, under KDE4, my application looks like this:

GTK widget set. Click to zoom.


Not exactly a KDE4 look-and-feel, but I have lots of applications (Gimp, GQView,  LibreOffice) that use GTK so it still looks native on my desktop, and GTK is a lot prettier than Metal.

Now why it is a good idea to write desktop applications instead of web applications, especially in Java, is something that Geertjan Wielenga talks about on his blog. Well worth the read.

Categorised as: howto, java, linux

Comments are closed.