views:

125

answers:

1

For a Java application, can I set the RenderingHints on a global basis? Currently, I've defined these in the paintComponent method as shown below. I would prefer, however, to set them once when the application starts and have them persist throughout the session.

@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);

Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}

Thanks.

+1  A: 

There's a system property for that.

Michael Borgwardt
That handles KEY_TEXT_ANTIALIASING, but what about KEY_ANTIALIASING?
Michael Myers
Looks like this will handle it for the text. However, as mmyers pointed out I've not seen an option for KEY_ANTIALIASING. System.setProperty("swing.aatext","true");
javacavaj