This post originated from an RSS feed registered with Java Buzz
by Scott Delap.
Original Post: More Advanced Synth
Feed Title: ClientJava.com
Feed URL: http://www.clientjava.com/archives/wireless_mobile.rdf
Feed Description: Client/Desktop Related Java Development
I'm going to repost two comments from yesterday's Advance Synth post so more people see them. First, the issue of Anti-Aliased fonts came up with Synth. Scott Violet of Sun was nice enough to provide the following solution:
Good article.
A handful of responses to various points:
. I'm surprised we missed making AA a property on the font. None-the-less it's easy to add after the fact. You can create a subclass of SynthGraphcsUtils, override the paintText method to set the aa hint and call super. You can then bind to this in the xml file similar to the background painter. Here's the code:
public class MySynthGraphicsUtils extends SynthGraphicsUtils {
public void paintText(SynthContext ss, Graphics g, String text,
int x, int y, int mnemonicIndex) {
Graphics2D g2 = (Graphics2D)g;
Object oldAAValue = g2.getRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
super.paintText(ss, g, text, x, y, mnemonicIndex);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
oldAAValue);
}
}
. Synth is hardly bug free, but it's certainly usable. As of this email there are ~10 open bugs against synth, a handful of which are documentation related. I will admit that 1.5 has more bugs as some have been fixed for 1.6.
Another comment dealt with dynamically sizing fonts:
Thanks for the responses in relation to antialias! I recently ran into this with my own application and went with a quick and useful hack: wraplf (http://wraplf.l2fprod.com/). This may not be necessary anymore with the code you provide here. I also had to add functionality in my application similar to Firefox's increase/decrease font size and discovered that there is no official mechanism for scaling fonts application wide in Swing. I ended up manually walking all UI defaults and looking for keys with "FONT" embedded in them, building a new FontUIResource based on the one for the key, "put"ting it back in for the key, and then calling updateComponentTreeUI. Still not 100% perfect, but pretty close.