Ugly/Non Anti-Aliased fonts in Java-Swing Applications

I've recently switched to Ubuntu and I've installed Oracle's Java JDK 8u45 (32 bit) using the webupd8team/java repository.

Everything seems to be working fine except that the Java-Swing applications are having broken and ugly fonts with no anti-aliasing. Changing the font doesn't work. Native applications like Gedit though having the same font are not affected (nor are non-Swing Java-applications like Eclipse); its only affecting Swing-based applications.

Screenshots: (jEdit v5.1)

Screenshot of jEdit

I'm running Ubuntu 15.04 (which is the latest version as of 2015-06-15). My Java version is 1.8.0_45 and 'java -version' gives the following output:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Server VM (build 25.45-b02, mixed mode)

I've tried the fixes given in similar questions (here and on other stackexchange sites) but they do not work. I've also added the following lines in the /etc/environment (as given here: https://wiki.archlinux.org/index.php/Java_Runtime_Environment_Fonts) but they are not giving me any apparent results.

JAVA_FONTS=/usr/share/fonts/truetype
_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on'

I'm sure there must be a fix for this. The same Java-Applications are working as they should on Windows-7.


This problem has long been fixed so I decided I should post the solution. Note that the problem is still there by default but it can be fixed by a parameter.

Adding this line:

_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true'

to /etc/environment fixes the issue.

This fix works as of Ubuntu 16.04 and OpenJDK 8u151 (haven't checked with Oracle JDK or Java 9).

Working example: enter image description here

Note: Some fonts and AA settings complicate the problem. In jEdit, I use the default Java fonts ("Dialog" as it's called) for everything. You can probably use a different font for the Text-Area but Dialog is the best for buttons, etc. The best Text-Area AA setting I've found is standard but your mileage may vary.