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

22 thoughts on “AntiAliasing and Java

  1. 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. 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:~$

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

  3. Cool! Thank you for posting this tip and reporting the bug.

    When defining environment variables, ~/.bash_profile is preferable to ~/.bashrc

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

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

Leave a reply to TheFunnyOne Cancel reply