Enables anti-aliasing for both text and other elements for the supplied 'g' Graphics object. - Java 2D Graphics

Java examples for 2D Graphics:Text

Description

Enables anti-aliasing for both text and other elements for the supplied 'g' Graphics object.

Demo Code


//package com.java2s;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

public class Main {
    /**/* ww  w . jav a 2s  .  com*/
     * Enables anti-aliasing for both text and other elements for the supplied
     * 'g' Graphics object.
     * 
     * @param g Graphics object on which anti-aliasing should be enabled.
     */
    public static void enableDefaultAASettings(Graphics g) {
        Graphics2D graphics2d = (Graphics2D) g;

        graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
    }
}

Related Tutorials