Text AA in Swing II
Hi I'm fairly experienced with Java and Swing, and I've done a commendable amount of Google research on antialiasing text in Swing components, but the closest thing I've come to a "code-saving" solution is this:
Now, this AA's the
Also, I have had suggestions to
Is there a "quick and dirty" solution to this? I have seen IntelliJ IDEA have the option to turn AA on/off during runtime, so I was thinking AA in Swing shouldn't take as much work as do the codes above (or does it?). Thanks in advance.
P.S.
I'm still on the topic of how to implement color themes in
JLabel txt = new JLabel("This is a test.") {
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
super.paint(g);
}
};Now, this AA's the
JLabel text, but I can't do a paint() on every Component I have to instantiate. I tried using the same solution above on the JFrame itself and then it loses the AA. :(Also, I have had suggestions to
extend the component classes and override paint() but this is just too iffy a proposition. To cut some code, I already tried this but it won't work:JButton button = new JButton();
smoothText(button);
void smoothText(Component c) {
Graphics2D g2 = (Graphics2D)c.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}Is there a "quick and dirty" solution to this? I have seen IntelliJ IDEA have the option to turn AA on/off during runtime, so I was thinking AA in Swing shouldn't take as much work as do the codes above (or does it?). Thanks in advance.
P.S.
I'm still on the topic of how to implement color themes in
MetalLookAndFeel. Thanks again.
