4

I have been using Dr Java on Ubuntu 14.04 and the GUI components all look very dated compared to the ones on Mac or Windows. Is there some way of updating this, or are all Java components in Linux just a bit old?

I'm using the JDK 8.0 Compiler from Oracle if that helps.

Here are some JButtons in Ubuntu

Mike
  • 73

2 Answers2

4

See: https://stackoverflow.com/questions/209731/how-do-i-force-get-to-use-gtklookandfeel-in-java-on-kde

You can hint to the JVM to use a different "Look and Feel" (LAF). There are a number of shipped LAFs available to the VM, and a few that are specific to some operating systems (i.e. The Windows LAF is only available on Windows.)

I suspect you are seeing the "Metal" LAF, which is pretty ugly (and happens to be the default if the developer does not specify a different LAF for a GUI app). You can try to force the GTK (or Nimbus, if you have the right version of the VM) LAF as suggested in this link. It will be something like this:

java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel YourAppName

You will have to substitute the application name for YourAppName. Or you might have to edit a file if your app is being started up via a Java launcher of some kind. The idea is that you want to add this Java define ("-Dswing.defaultlaf=...") to the VM arguments somehow.

Since you are using the Oracle Java 8 VM, you might even want to try the nice new javax.swing.plaf.nimbus.NimbusLookAndFeel.

Refs: How to Set the Look and Feel

1

I hope you need Java to use GTK look and feel. As jdv answered you can set it at the runtime or you can set it for all the Java swing applications using the following technique:

Step 1: In Java 8 this file is not available by default. So the given command will create a new one. According to your Java version, change the path.

gksu gedit /usr/lib/jvm/jdk1.8.0_60/jre/lib/swing.properties

Step 2: Add the following line in the file and save the file

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

Now run the application, you will get a native allok and feel for all the swing applications.

Eventhough it is not required for your Calculator application, enabling Global Menu will improve the look and feel of Java applications. To enable Global menu:

Ste 1: Install Jayatana using the following set of commands:

From Ubuntu 15.04 it is installed by default.

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

Step 2: Disable gloabl Jayatana configuration

sudo rm /usr/share/upstart/sessions/jayatana.conf

Step 3: When you run a Java application, use the following command

java -jar -javaagent:/usr/share/java/jayatanaag.jar <file-name>

Credits to:

How can I get a java apps to use the GTK+ theme?

Global Menu Support for Java Applications in Ubuntu

Gobinath
  • 3,392