AntiAliasing and Java

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/

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).


22 responses to this post.

  1. 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.


  2. Should ths be filed as a bug report and fixed in the packages?

    Surely that is a no brainer to make anti aliasing default?


  3. […] 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 […]


  4. 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/
    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)


  5. Posted by Matěj Cepl on February 26, 2010 at 2:22 pm

    sorry, PEBKAC … cursed smart quotes!!!


    • 🙂 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 😛


  6. It was a cool tip!


  7. 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


  8. Posted by Ravishankar on March 11, 2010 at 9:33 am

    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..



  9. very informative..thanks a lot..james


  10. Posted by TheFunnyOne on May 6, 2011 at 8:41 pm

    Thanks for the tip, it worked out well for me.


  11. […] _JAVA_OPTIONS=”-Dawt.useSystemAAFontSettings=on”加入~/.bashrc就可以了。 (尚未评分)  Loading […]


  12. 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.


  13. Thanks 🙂 It helped me a lot.


Leave a Reply to Matěj Cepl Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: