Java Graphics2D .setRenderingHints (Map <?,?> hints)
Syntax
Graphics2D.setRenderingHints(Map <?,?> hints) has the following syntax.
public abstract void setRenderingHints(Map <?,?> hints)
Example
In the following code shows how to use Graphics2D.setRenderingHints(Map <?,?> hints) method.
//w w w .j a v a 2 s . c om
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Main extends JPanel {
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Font f = new Font ("Arial", Font.PLAIN, 48);
g2.setFont (f);
g2.drawString ("www.java2s.com", 10, 60);
RenderingHints rh = g2.getRenderingHints ();
rh.put (RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHints (rh);
g2.drawString ("Antialiased text", 10, 120);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.add(new Main());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(20, 20, 500, 500);
frame.setVisible(true);
}
}
Home »
Java Tutorial »
java.awt »
Java Tutorial »
java.awt »