Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

Activating anti-aliasing in Swing

Thread view: 
jonck@vanderkogel.net - 26 May 2005 12:51 GMT
Hi all,
I was reading through the following blog
(http://weblogs.java.net/blog/joshy/archive/2005/05/the_reponse_to.html)
where I read the following:
"Fonts are another one of Metal's areas where insistence on backward
compatibility is hurting Swing. Metal still has those big bold chunky
fonts by default that scream "amateur", and I've seen Sun's response in
the past being "some clients depend on these font sizes and types". Sun
does all the hard work technically - Swing can pick up system fonts and
font sizes, it can anti-alias fonts, and so on, *IF* you use the
correct command-line option, because by default it's
backward-compatible. Boom - most people never see the change.
It was a similar story with J2SE 1.4 and assertions - they were
provided but were off by default. In my team makefiles are maintained
by one guy. If assertions were disruptive (they were not), he would
have changed javac options to be backward compatible and none else
would have noticed. As it is, J2SE 1.4 was backward compatible, we
smoothly transitioned to it without a change, and even today developers
are not getting indoctrinated into using assertions because it is off
by default."

So what he's saying here is that through a simple command-line option
we have anti-aliasing? That would be really cool, however, I searched
through the command-line options that are posted by Sun and could not
find anything about this subject. I tried responding to the author on
the java.net site, but for some reason even after logging in it would
not allow me to post comments.

Therefore my question is, does anyone know which command-line option
the author of the blog was referring to?

Thanks, Jonck
Christian Kaufhold - 26 May 2005 13:07 GMT
> So what he's saying here is that through a simple command-line option
> we have anti-aliasing? That would be really cool, however, I searched
[quoted text clipped - 5 lines]
> Therefore my question is, does anyone know which command-line option
> the author of the blog was referring to?

java -Dswing.aatext=true Main

Christian
Bill Tschumy - 26 May 2005 14:31 GMT
>> So what he's saying here is that through a simple command-line option
>> we have anti-aliasing? That would be really cool, however, I searched
[quoted text clipped - 9 lines]
>
> Christian

This is also, apparently, an "undocumented" feature that was added for
testing only.  Sun has said it could disappear in the future.  I wouldn't get
too dependent on it.

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

jonck@vanderkogel.net - 26 May 2005 15:13 GMT
> java -Dswing.aatext=true Main

Thank you for your suggestion. The JVM is accepting -Dswing.aatext=true
as a valid option, however, it does not appear to do anything, all my
Swing components still render the same. Also, from what Bill said, it
seems like it's not something to use in production code.

At the moment I'm having to override paintComponent for every Swing
component I use to get anti-aliasing working:

public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    super.paintComponent(g2d);
}

Is this really the only way to get anti-aliasing in Swing at the moment
(using 1.4.2), or is there a more elegant way that someone knows of?

Thanks, Jonck
Bill Tschumy - 26 May 2005 22:15 GMT
>> java -Dswing.aatext=true Main
>
> Thank you for your suggestion. The JVM is accepting -Dswing.aatext=true
> as a valid option, however, it does not appear to do anything, all my
> Swing components still render the same. Also, from what Bill said, it
> seems like it's not something to use in production code.

<snip>

> Is this really the only way to get anti-aliasing in Swing at the moment
> (using 1.4.2), or is there a more elegant way that someone knows of?
>
> Thanks, Jonck

If you are using 1.4.2, that is the reason the "aatext" hack  doesn't work
for you.  This is a 1.5 feature.

Signature

Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Boudewijn Dijkstra - 26 May 2005 22:25 GMT
>> java -Dswing.aatext=true Main
>
[quoted text clipped - 15 lines]
> Is this really the only way to get anti-aliasing in Swing at the moment
> (using 1.4.2), or is there a more elegant way that someone knows of?

There is a mechanism that provides the Graphics objects to these
paintComponent methods.  Maybe you can intercept the object before it is
passed to the method, giving you the opportunity to set a few default hints.
Richard Wheeldon - 27 May 2005 20:27 GMT
> At the moment I'm having to override paintComponent for every Swing
> component I use to get anti-aliasing working:

> Is this really the only way to get anti-aliasing in Swing at the moment
> (using 1.4.2), or is there a more elegant way that someone knows of?

WrapLF is slightly more elegant. It basically automates the
above process using a custom look and feel.

http://wraplf.l2fprod.com/

Richard
jonck@vanderkogel.net - 30 May 2005 17:49 GMT
Thanks for the comments guys.

The wraplf project seems a smart way of doing things, though I spotted
a lot of errors right away trying to use it in conjunction with the
JGoodies L&F.

So I guess I'll stick to the manual setting of rendering hints untill
Java 1.5 comes to OS X.

Kind regards, Jonck


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.