Many Java Apps don't use anti-aliased fonts by default, despite the capability of Swing to provide them. How can you coerce an arbitrary java application to use AA fonts? (both for applications I'm running, and applications I'm developing)
4 Answers
If you have access to the source, you can do this in the main method:
// enable anti-aliased text:
System.setProperty("awt.useSystemAAFontSettings","on");
or, (and if you do not have access to the source, or if this is easier) you can simply pass the system properties above into the jvm by adding these options to the command line:
-Dawt.useSystemAAFontSettings=on
-
this method does not work for Substance look and feel, do you have idea about this ? Mar 9, 2012 at 17:46
-
-
If you're working with the Graphics apis, this may help: docs.oracle.com/javase/tutorial/2d/text/renderinghints.html Mar 16, 2014 at 20:16
-
9Setting
awt.useSystemAAFontSettings
toon
means use anti-aliasing without sub-pixel rendering which is most of the time (when using LCD display) not preferred. Instead uselcd
value. See wiki.netbeans.org/FaqFontRendering Nov 26, 2014 at 14:30 -
1The first setting alone works. That second setting does not need to be used. It's an undocumented, private setting, that has been removed from the JRE. See details: bugs.java.com/bugdatabase/view_bug.do?bug_id=6391267– clemepNov 19, 2018 at 16:22
Swing controls in the latest versions of Java 6 / 7 should automatically abide by system-wide preferences. (If you're using the Windows L&F on a Windows OS then text should render using ClearType if you have that setting enabled system-wide.) So perhaps one solution could simply be: enable the native Look and Feel?
In applications you're developing, if you render your own text directly, you also need to do something like this (at some point before calling Graphics.drawText
or friends):
if (desktopHints == null) {
Toolkit tk = Toolkit.getDefaultToolkit();
desktopHints = (Map) (tk.getDesktopProperty("awt.font.desktophints"));
}
if (desktopHints != null) {
g2d.addRenderingHints(desktopHints);
}
Reference: http://weblogs.java.net/blog/chet/archive/2007/01/font_hints_for.html
For the record, I have found out that in my windows 7 machine,
- If I don't use this in my code, I get the nice ClearType subpixel rendering.
- But if I use this, I get the classical black-and-white antialiasing which is much uglier.
So this code should be used carefully. I guess it will stop being needed at all when all Linux users have updated to the versions of OpenJDK that handle aliasing well by default.
-
7Try System.setProperty("awt.useSystemAAFontSettings", "lcd"); and you should get ClearType.– DomchiMay 3, 2011 at 0:55
-
As a linux and windows user I do not like "cleartype". I purposely disable it. Dec 5, 2014 at 17:25
thanks for the info. I was wondering about this myself. I use SoapUI(www.eviware.com) and it does NOT, by default, use AA text. I added -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true to the batch file that launches it BUT that did NOT make a difference. Guess, I have to ask in their forum.
-
it may be interpreting the arguments as pertaining to the application instead of the jvm -- you may need to dig into the bat file a bit deeper. (or it may not work for all apps... if so, please let me know / vote my answer down..) Oct 7, 2008 at 20:05
-
1I was able to get this to work by editing the .sh launch file so that the last line read: java -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dsoapui.properties=soapui.properties -Dgroovy.source.encoding=iso-8859-1 -cp $SOAPUI_CLASSPATH com.eviware.soapui.SoapUIPro $* Oct 7, 2008 at 20:14
-
1I believe you could do the same with the soapui bat file by adding the -D.... params listed here to the JAVA_OPTS line, or just specifying JAVA_OPTS=-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true in the surrounding environment Oct 7, 2008 at 20:16
-
For SoapUI on Windows, I edited the SoapUI-5.0.0.vmoptions file in the "C:\Program Files (x86)\SmartBear\SoapUI-5.0.0\bin" folder and added -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true as the last line.– AidanJun 26, 2014 at 23:52
-
Also, the order of arguments can make a difference, you need to add the arguments before any
-jar mycooljar.jar
– bmurauerOct 2, 2017 at 7:09