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).
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.
Thanks 🙂
Should ths be filed as a bug report and fixed in the packages?
Surely that is a no brainer to make anti aliasing default?
I agree! So: https://bugzilla.redhat.com/show_bug.cgi?id=568640
I hope it gets some attention!
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:~$
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 😛
It was a cool tip!
Thanks!
Cool! Thank you for posting this tip and reporting the bug.
When defining environment variables, ~/.bash_profile is preferable to ~/.bashrc
Thanks! 🙂
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
AFAIK, it is enabled by default in Windows! Is your jdk old?!
very informative..thanks a lot..james
javajobs.net
🙂 You’re welcome
Thanks for the tip, it worked out well for me.
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.
🙂 You’re welcome!
Thanks 🙂 It helped me a lot.
You’re welcome!