Hi,
I'm interested in making my JLabels/JTextFields/etc use anti-aliased
text. I know you can get anti-aliased text in Java2D but for some
reason, I don't seem to find any documentation on enabling anti-aliasing
on Swing components.
The only way I can think of getting anti-aliased text at the moment is
to subclass the component, override the paintComponent and set the
graphics object to use anti-aliasing. That's not easy and it means that
I need to subclass all Swing components that I intend to use.
Is there an easier way of enabling anti-aliased text on components? Does
a L&F exist that automatically does this?
Thanks,
Wee-Jin
Knute Johnson - 23 May 2004 05:06 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> graphics object to use anti-aliasing. That's not easy and it means that
> I need to subclass all Swing components that I intend to use.
That's how you have to do it.
> Is there an easier way of enabling anti-aliased text on components? Does
> a L&F exist that automatically does this?
Unfortunately no.
> Thanks,
> Wee-Jin

Signature
Knute Johnson
email s/nospam/knute/
Molon labe...
Jan Sauerwein - 23 May 2004 08:05 GMT
Hello Wee Jin,
> I'm interested in making my JLabels/JTextFields/etc use anti-aliased
> text. I know you can get anti-aliased text in Java2D but for some reason,
[quoted text clipped - 5 lines]
> object to use anti-aliasing. That's not easy and it means that I need to
> subclass all Swing components that I intend to use.
Not an easier but a better way. The Components of swing do not implement
their drawing by themself, they use UI delegates for that. Take a look at
javax.swing.plaf to find the base classes for a look and feel. There you
can make your own UI delegates in your own look and feel and use it. Do not
override the paintComponent method because then it is not possible to
change the laf.
Jan Sauerwein
minsc - 23 May 2004 11:11 GMT
Hi!
> Is there an easier way of enabling anti-aliased text on components? Does
> a L&F exist that automatically does this?
I've been looking into this only recently and yes, a lookandfeel exists!
There's a sourceforge project named 'smoothmetal' that just copies Metal
and Windows lookandfeels and just enables the use of rendering hints
(and AA as a result). You'll find it here : http://smoothmetal.sf.net.
I must say however that I don't use it anymore because, to be hontest, I
don't like how it looks. I find the AA-effect much too blurry.
I've also heard that in Java 1.5 (tiger) AA rendering of components
would be a global setting. Though I have 1.5 beta installed, I haven't
looked for it yet.
My regards,
Pieter Bonne.
Thomas Weidenfeller - 24 May 2004 07:26 GMT
> The only way I can think of getting anti-aliased text at the moment is
> to subclass the component, override the paintComponent and set the
> graphics object to use anti-aliasing. That's not easy and it means that
> I need to subclass all Swing components that I intend to use.
I never researched the following idea further, I am not particular
interested in it, but if you do, please report back here.
Based on the way Swing works, it should be sufficient to only set the
necessary rendering hint on the container in use. When the container is
painted, it passes a Graphics2D context to all its children. It should
be possible to override the container's paint() to set the rendering
hint before the Graphics2D is handed down to the children.
Once done, you only need to exchange the containers like JPanel with
your own version. There should be no need to override all Swing components.
/Thomas
Karsten Lentzsch - 24 May 2004 08:36 GMT
> I'm interested in making my JLabels/JTextFields/etc use anti-aliased
> text. I know you can get anti-aliased text in Java2D but for some
> reason, I don't seem to find any documentation on enabling anti-aliasing
> on Swing components.
Note that anti-aliasing can increase or decrease
the legibility and readability in screen design.
That depends on the rasterizer, font, font size,
font type, font hints, screen resolution (not size),
display hardware, etc.
As a rule of thumb you can enable AA if it's enabled
in the OS if you are using exactly the same font from
the same font vendor as used in the OS.
And you can enable it for fonts larger than 16 pt
in environments with a resolution higher than 72 dpi.
There are some cases, where one AA algorithm
increases the legibility and another decreases it.
If the ClearType subpixel AA is enabled in Win XP
it doesn't follow that the Java2D rasterizer does
a good job on that display hardware with the font used.
On the majority of Windows desktops you still
do better with the Java2D AA disabled. I force AA
for larger font sizes only, for example in headers, see
http://www.jgoodies.com/freeware/bookfinder/images/bookfinder-0_9.png
Hope this helps,
Karsten Lentzsch
Wee Jin Goh - 24 May 2004 09:14 GMT
> Hi,
>
[quoted text clipped - 13 lines]
> Thanks,
> Wee-Jin
OK, just a follow-up. I've tried using the smooth metal look and feel
that was suggested. I don't think I want AA anymore since it really does
make the text look hard to read. Text looks alright with the Metal look
and feel, but with the WinXP look and feel, the text becomes practically
illegible!
Guess I'll just stick to non-AA fonts for now. Thanks for all the great
replies!
Regards,
Wee Jin