3
Use the class RenderingHints
:
private static final RenderingHints HINTS = new RenderingHints(null);
static {
HINTS.put(KEY_ALPHA_INTERPOLATION, VALUE_ALPHA_INTERPOLATION_QUALITY);
HINTS.put(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
HINTS.put(KEY_COLOR_RENDERING, VALUE_COLOR_RENDER_QUALITY);
HINTS.put(KEY_INTERPOLATION, VALUE_INTERPOLATION_BICUBIC);
HINTS.put(KEY_STROKE_CONTROL, VALUE_STROKE_NORMALIZE);
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHints(HINTS);
// Prossiga com seu desenho aqui.
}
All these keys and values are added with import static java.awt.RenderingHints.*
. The most important thing is KEY_ANTIALIASING
and the VALUE_ANTIALIAS_ON
that activates anti-aliasing.
For more details, see the TCC I did in this area in 2007.