You are not logged in.

#1 2009-05-26 22:09:47

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Make Java Swing applications use your current GTK 2.0 Look and Feel

I stumbled across this article last night about making your Swing-based applications theme themselves according to your current GTK 2.0 Look and Feel (laf).  Essentially, all you need to do is create a file in your `$JAVA_HOME/jre/lib/' directory called "swing.properties" (for me, this was `/usr/lib/jvm/java-1.6.0-openjdk/jre/lib/swing.properties'), and put this inside:

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

... then, whenever you run a Swing application with `java ApplicationName', it will use your current GTK 2.0 theme to draw its widgets -- pretty nifty!  However, for me, it's not perfect as the font size is a little too large, but it's still a HUGE improvement over the old metal theme (or whatever it is Swing uses by default).  You can alternately launch Swing applications with your GTK theme manually with `java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel ApplicationName'.

To configure Netbeans to use your theme, append this to the end of the `netbeans_default_options' variable in your "netbeans.conf" file (/usr/share/netbeans/etc/netbeans.conf):

--laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel

... so it looks something like this:

netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m ... --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel"

... but be warned, this made Netbeans horribly ugly on my end.  I use Kate and/or Vim for most of my Java programming anyway smile

If anybody's willing to check it out, let me know your experience; I'll play around and see if I can get the font size issue resolved and post my results later.

Note: This will work with the gtk-qt-theme-engine on KDE, as that's what I'm using now.


Dylon

Offline

#2 2009-07-08 01:34:33

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

Thanks for giving the heads up on this.

Instead of swing.properties, I add the following to my .bashrc:

export _JAVA_OPTIONS=-Dawt.useSystemAAFontSettings=on -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

Offline

#3 2011-01-14 00:58:58

reed1
Member
Registered: 2011-01-14
Posts: 29

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

gladstone wrote:

Thanks for giving the heads up on this.

Instead of swing.properties, I add the following to my .bashrc:

export _JAVA_OPTIONS=-Dawt.useSystemAAFontSettings=on -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel

Worked perfectly , thanks big_smile

Offline

#4 2011-02-02 23:30:21

marines
Member
From: Poland
Registered: 2010-08-21
Posts: 20
Website

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

None of these tips helped. Any clue why? Is there any package needed for that?

Offline

#5 2012-02-19 00:54:06

Occi
Member
From: Norway
Registered: 2011-09-18
Posts: 24
Website

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

Sorry for resurrecting an old thread, but I'd just like to say that Netbeans can be configures way further than just simple changes in swing. You can for example use Nimbus, and get a result like this. You simply add what is said in that page to your /usr/share/netbeans/etc/netbeans.conf, but remember to use full path (pref. absolute I guess) for both files. Both files are also easily changeable. The .jar-file can be changed by running it with java -jar nimrodlf.jar.

This is my setup with Netbeans, and it's the default DarkGrey-theme.

Offline

#6 2012-02-19 23:37:39

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

marines wrote:

None of these tips helped. Any clue why? Is there any package needed for that?

Are you running Oracle JDK 6 or OpenJDK 7? If you're on 7, there's a different package name for the Nimbus LAF (javax.swing.plaf.nimbus.NimbusLookAndFeel) and likely as well for the GTK LAF. Try javax.swing.plaf.gtk.GTKLookAndFeel (not tested this myself).

Offline

#7 2012-02-20 07:35:23

marines
Member
From: Poland
Registered: 2010-08-21
Posts: 20
Website

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

I'm pretty sure I was running 6 a year ago. xD Anyway I've stopped strugling to change L&F.

Offline

#8 2012-02-21 20:29:17

twelveeighty
Member
From: Alberta, Canada
Registered: 2011-09-04
Posts: 1,096

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

Oh jeez - I never realized that was a post from 2011. I hate these thread resurrections.

Offline

#9 2012-02-28 10:19:08

Phitherek_
Member
From: Poland
Registered: 2008-11-08
Posts: 36
Website

Re: Make Java Swing applications use your current GTK 2.0 Look and Feel

The export trick works for me, you forgot to put the value in ''.


Posted by Phitherek_

Offline

Board footer

Powered by FluxBB