Whenever I ran a Swing Java application on my Fedora, I really hated its ugly appearance of fonts and I was always wondering why Java doesn’t support font anti aliasing in Linux. But I’ve never searched for it in the web, since I thought that if such support exists, it should be enabled already! Today, I’ve decided to look for it, and I found the answer very quickly!! Java already supports font anti-aliasing in Linux, it is simply disabled by default (at least in OpenJDK, in Fedora!). And the solution is simple, just set the desired option in the _JAVA_OPTIONS environment variable. e.g.:
export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on"
and then run your Java application. The GUI will be much more desirable then! I’d suggest adding this option globally. You can simply put the above line in your ~/.bashrc (if you are using bash!), or put it in a file in the /etc/profile.d/ directory. For example, this is the contents of my /etc/profile.d/tune.sh:
export HISTCONTROL=ignoredups export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on"
(The first option is not related to the current discussion, but I think it is desirable for most users. With this option, bash will merge same sequential history contents into one history item)
I also like to talk about an interesting application but I keep it for a separate post! 😛
Have fun!
Update: I think it is fair to mention the original link which helped me: Java Swing anti-aliasing. Also, fortunately there is already an update for openjdk package in fedora updates-testing repository which has anti-aliasing enabled by default (at least for Swing apps. You might still need to use the above option for Awt applications).
Posted by Chris on February 26, 2010 at 8:10 am
What a coincidence… I ran across this problem for the first time about 3 days ago when I gave Netbeans a try on Fedora 12 (I’m an Eclipse guy). I was horrified by the fonts… they were almost unreadable. I found and used the ~/.bashrc method and it worked like a charm.
Good post! I’m sure more people are out there using Java apps on Fedora with a look of disgust on their faces right now, and hopefully they’ll run across this.
Posted by Hedayat on February 26, 2010 at 10:49 am
Thanks 🙂
Posted by You on February 26, 2010 at 8:37 am
Should ths be filed as a bug report and fixed in the packages?
Surely that is a no brainer to make anti aliasing default?
Posted by Hedayat on February 26, 2010 at 11:50 am
I agree! So: https://bugzilla.redhat.com/show_bug.cgi?id=568640
I hope it gets some attention!
Posted by Turning AntiAliasing on for Java Applications in X11 « Azmo’s Weblog on February 26, 2010 at 1:37 pm
[…] my eyes could just not bear the uglyness of the fonts for more than 30 seconds. Thanks to this post by Hedayat and knowing I can turn on AntiAliasing by putting this into my […]
Posted by Matěj Cepl on February 26, 2010 at 2:21 pm
johanka:~$ export _JAVA_OPTIONS=”-Dawt.useSystemAAFontSettings=on”
johanka:~$ /home/matej/.java/jsword-1.6/BibleDesktop.sh
Picked up _JAVA_OPTIONS: ”-Dawt.useSystemAAFontSettings=on”
Unrecognized option: ”-Dawt.useSystemAAFontSettings=on”
Could not create the Java virtual machine.
johanka:~$ unset _JAVA_OPTIONS
johanka:~$ java -version
java version “1.6.0_0”
OpenJDK Runtime Environment (IcedTea6 1.6) (fedora-1.14.b16.el6-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
johanka:~$
Posted by Matěj Cepl on February 26, 2010 at 2:22 pm
sorry, PEBKAC … cursed smart quotes!!!
Posted by Hedayat on February 26, 2010 at 3:26 pm
🙂 Yes, these quotes had hit me in past too. Thanks for the report, I’ve changed the formatting so that copy-pasting should work now. Unfortunately they appear a bit ugly in the blog 😛
Posted by آرمان on February 26, 2010 at 3:46 pm
It was a cool tip!
Posted by Hedayat on February 26, 2010 at 4:13 pm
Thanks!
Posted by Allen Halsey on February 26, 2010 at 11:08 pm
Cool! Thank you for posting this tip and reporting the bug.
When defining environment variables, ~/.bash_profile is preferable to ~/.bashrc
Posted by Hedayat on February 26, 2010 at 11:49 pm
Thanks! 🙂
Posted by Ravishankar on March 11, 2010 at 9:33 am
Folks,
Please help me out in antialiasing with windows.MY swing application is based upon a frame view .I want a solution to apply for the entire application..
Thanks,
Ravi
Posted by Hedayat on March 11, 2010 at 10:38 pm
AFAIK, it is enabled by default in Windows! Is your jdk old?!
Posted by james smith on April 21, 2010 at 11:30 am
very informative..thanks a lot..james
javajobs.net
Posted by Hedayat on May 7, 2010 at 10:06 am
🙂 You’re welcome
Posted by TheFunnyOne on May 6, 2011 at 8:41 pm
Thanks for the tip, it worked out well for me.
Posted by Ubuntu下为Java程序开启Anti Aliasing Font反锯齿字体只要将export JAVA OPTIONS= Dawt useSystemAAFontSettings=on 加入~... - 网摘 - ILOST.INFO on August 31, 2011 at 7:25 am
[…] _JAVA_OPTIONS=”-Dawt.useSystemAAFontSettings=on”加入~/.bashrc就可以了。https://hedayatvk.wordpress.com/2010/02/26/antialiasing-and-java/ (尚未评分) Loading […]
Posted by Serge on September 21, 2012 at 7:52 am
ZOMG! It’s 09/2012 and openJDK still haven’t this feature enabled by default at least in my distro!
Thank you a lot, you’ve saved my eyes.
Posted by Hedayat on September 29, 2012 at 11:59 pm
🙂 You’re welcome!
Posted by Krystian Juskowiak on August 6, 2014 at 6:49 pm
Thanks 🙂 It helped me a lot.
Posted by Hedayat on August 6, 2014 at 11:33 pm
You’re welcome!