A technique of making fonts look smoother on screen by using blended colours in the
pixels around the edges of letters. It fools the eye into thinking that the edges are
sharper than they really are.
You can get W2K and XP
to anti-alias with Start ⇒ Control Panel ⇒ Display
⇒ Effects ⇒ Smooth edges of screenfonts. You can get
Vista to anti-alias with Start ⇒
Control Panel ⇒ System and Maintenance ⇒ Performance Information and Tools
⇒ Adjust Visual Effects (on left) ⇒ smooth edges of screen
. You can get Vista
to anti-alias with Start ⇒ Control Panel ⇒ System and
Maintenance ⇒ Performance Information and Tools ⇒ Adjust Visual Effects (on
left) ⇒ smooth edges of screen fonts.
With an LCD (Liquid Crystal Display) monitor, you want subpixel anti-aliasing called
ClearType. To turn it on click Start ⇒ Control Panel ⇒
Appearance and Personalization ⇒ Personalization ⇒ Windows color and
appearance ⇒ Open classic colour and appearance ⇒ Effects ⇒
Without anti-aliasing, you will see jagged diagonal lines especially in the large
sizes of spidery fonts with thin diagonal lines (e. g. Bodoni, Book Antiqua,
Garamond, Serif and Zapf Calligraphic) especially on the capital W. Sun, even when
anti-aliasing, pays no attention to the font rendering hints. This why small font
sizes are so grungy looking. Anti-aliasing is primarily to make large font sizes look
What Does Anti-aliasing Look Like?
You can compare the same
fonts anti-aliased and plain using the FontShower for Swing amanuensis which will display
fonts in various sizes and colours with and without anti-aliasing and in the
FontShower for AWT Applet
in canvas mode. You are certain to see fonts without anti-aliasing in the FontShower for AWT Applet in canvas
mode under W95, W98, Me, NT and W2K. You are certain to see
anti-aliasing in the FontShower
for Swing under XP, W2003, Vista, W2008, W7-32, W7-64, W8-32 and W8-64.
The font where the differences are most obvious is DPCustomMono2.
How Anti-Aliasing looks
The further back you stand, the more the samples look alike. Anti-aliasing is
a similar sort of blurring that ironically creates the illusion of sharpness.
Several influences combine to decide whether you will get anti-aliasing:
- Whether your OS/Windowing system supports anti-aliasing.
- Whether you have anti-aliasing turn on system wide.
- Whether your browser is turning on anti-aliasing.
- Whether the program is turning on anti-aliasing.
- Whether the font supports anti-aliasing.
- Whether your text contains unusual characters. Some will turn off
Anti-aliasing in Java version 1.2
To anti-alias fonts in AWT (Advanced Windowing Toolkit), you have to go through a
gambit like this in your Canvas
There is another technique that uses an undocumented Oracle class.
It won’t do you any good to override the paint
method of a peered Component such as Label, TextField or TextArea since the rendering is handled by the peer. Whether they are
anti-aliased is determined by the OS (Operating System)
Anti-aliasing in Java version 1.3
in Swing is similar to AWT, except that you override paintComponent instead of paint.
Metal LAF (Look And Feel)
adds anti-aliasing to various Oracle LAFs (Look And Feels).
WrapLF is a
LAF that lets you insert
your own code.
Anti-aliasing in Java version 1.5
Java version 1.5 you don’t have to override
Since Java version 1.5, it is possible to set the system
property globally with swing.aatext=true. You can do that
with java.exe -Dswing.aatext=true
on the command line. Unfortunately the results are not always desirable. Sometimes
small fonts look worse anti-aliased.
Anti-aliasing in Java version 1.6
The Java 1.6,
has yet another anti-aliasing scheme, one that allows sub-pixel anti-aliasing that
takes advantage of the geometry of the tiny red, green and blue phosphor dots on a
CRT (Cathode Ray Tube), or the equivalent dots on an
LCD panel, that
make up each pixel. Microsoft uses a scheme like this in Vista
they call ClearType. In
Java version 1.6 there is a system property called awt.useSystemAAFontSettings you can use to control anti-aliasing.
Possible values include:
In Java version 1.6 or later there are also new values to
use in setRenderingHints key and value, including
VALUE_ANTIALIAS_OFF to turn anti-aliasing off.
use ClearType style sub-pixel anti-aliasing.
no anti-aliasing. Fast with jaggies.
Gnome Best shapes/Best contrast. Not available in Windows.
Windows standard anti-aliasing.
- Rendering character \u0e3f in a JTextArea inhibits antialiasing, ditto \ufdfc. \u0e3f is a Thai Baht
currency sign like a capital B with a line through it. \ufdfc is the Yemeni Rial currency sign. It looks like Arabic
script. Using one of these characters turns off anti-aliasing for the entire
JTextArea. They seem to have no such effect in
drawString or with TextArea.
This strange behaviour has been observed both in Win2K and Linux.
I reported this to Oracle and they
explained the anomaly is a feature.
Internally when Swing sees a Thai or Arabic character, it switches to using a
TextLayout for rendering. A TextLayout is created with a FontRenderContext, and the anti-aliasing Component of that FontRenderContext is
applied when rendering too. In other words the usual anti-alias gambit does not
work because it is anti-aliasing the wrong Component
when you have Thai or Arabic characters.
- Java version 1.6 defaults its anti-aliasing to
whatever the OS desktop setting is, making it behave like
Oracle’s Javadoc on RenderingHints
class : available:
Oracle’s Technote Guide on anti-aliasing