36

Is there a way to get java apps to use my gtk theme?

David Planella
  • 15,420
  • 11
  • 77
  • 141
RolandiXor
  • 51,091
  • 31
  • 161
  • 256

3 Answers3

28

You can try to set Java's default look and feel to GTK:

Open a terminal ( Ctrl + Alt + T ) and paste the upper one for openjdk and the lower one for sun java .

gksu gedit /usr/lib/jvm/java-6-openjdk/jre/lib/swing.properties

gksu gedit /usr/lib/jvm/java-6-sun/jre/lib/swing.properties

  • Follow the comment in that file and remove the hash sign, so it looks like:

    # uncomment to set the default look and feel to GTK
    swing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
    
  • Save and restart the java app.

Before and after:

htorque
  • 63,950
  • 40
  • 194
  • 219
  • 1
    didn't fix it, but still very useful for me :) thanks! – RolandiXor Jan 16 '11 at 21:50
  • 2
    Thanks. I used this as a tip but instead did; ```UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");``` which does not require any configuration file editing. – xconspirisist Sep 15 '13 at 18:56
  • @RolandiXor If this didn't work, that means the developer of the app hardcoded the look and feel. Nothing you can do about that, unless it is open-source. :( – jobukkit Nov 19 '13 at 15:01
  • 1
    It hepled me to solve "jdk bold font" bug. Thank you. – MInner Jun 26 '14 at 16:23
  • Didn't fix for universalmediaserver on Ubuntu Mate 14. – NicolasSmith May 09 '17 at 11:37
  • No dice on Ubuntu Mate, not even with OpenJDK Java 8 Policy Tool, which I don't believe it's hardcoded... – Franko Mar 17 '18 at 13:35
  • swing.properties file seems to be ignored (open-jdk 8 & openjdk-11) even if you put swing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel in it (which seems to be the correct variable to set). Setting _JAVA_OPTIONS in your environment (see below) seems more promising – ChrisAga Apr 04 '20 at 07:39
16

If you have already tried the above solutions - try using this (helped me on Xfce):

  1. export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel'

  2. Then launch in this terminal your app.

  3. If you are satisfied with your result - add this line to your ~/.profile file.
yanpas
  • 543
  • 4
  • 16
  • 1
    Putting this into `~/.profile` didn't work for me, but I put `_JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel -Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel"` into `/etc/environment` (note the usage of double rather than single quotes and the missing `export`, otherwise the magic doesn't work). – Photon Mar 09 '17 at 13:03
  • Works fine with SweetHome3D and Ubuntu 18.04 – NicolasSmith Feb 17 '19 at 07:29
  • Thanks a lot for the help. If anyone is experiencing Swing application crash like mine, consider removing the last option `Dswing.crossplatformlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel` – Puspam Mar 12 '22 at 10:46
7

If you are the developer or it's an open source, an alternative way is to change the look and feel of the application. Insert the below code in the main method.

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("com.sun.java.swing.plaf.gtk.GTKLookAndFeel".equals(info.getClassName())) {   
       javax.swing.UIManager.setLookAndFeel(info.getClassName());
       break;
     } 
}

This might be also helpful.