The five new fields in java.awt.RenderingHints class: : RenderHints « 2D Graphics « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » 2D Graphics » RenderHints 
16.45.3.The five new fields in java.awt.RenderingHints class:Previous/Next
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class TextQualityDemo {
  public static void main(String[] args) {
    JFrame frame = new JFrame("LCD Text Demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setPreferredSize(new Dimension(630460));
    frame.setContentPane(new MyPanel(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF));
    frame.pack();
    frame.setVisible(true);
  }
}

class MyPanel extends JPanel {
  private Object hintValue;

  public MyPanel(Object hintValue) {
    this.hintValue = hintValue;
    this.setPreferredSize(new Dimension(300100));
    String title = hintValue.toString();
    Border border = new TitledBorder(title);
    this.setBorder(border);
  }

  public void paintComponent(Graphics g) {
    Dimension d = this.getSize();
    BufferedImage backBuffer = (BufferedImagethis.createImage(d.width, d.height);
    Graphics2D g2 = backBuffer.createGraphics();

    g2.setColor(Color.WHITE);
    g2.fillRect(00, d.width, d.height);

    g2.setColor(Color.BLACK);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, hintValue);

    g2.drawRect(00, d.width - 1, d.height - 1);

    g2.drawString("abcdefghijklmnopqrstuvwxyz"2040);
    g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"2060);
    g2.drawString("1234567890-=!@#$%^&*()_+,./<>?"2080);

    g.drawImage(backBuffer, 00this);
  }
}
16.45.RenderHints
16.45.1.Handle screen updatesHandle screen updates
16.45.2.Set Rendering Hint and EllipseSet Rendering Hint and Ellipse
16.45.3.The five new fields in java.awt.RenderingHints class:
16.45.4.RenderingHints.KEY_TEXT_ANTIALIASING
16.45.5.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR
16.45.6.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB
16.45.7.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR
16.45.8.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB
16.45.9.RenderingHints.VALUE_TEXT_ANTIALIAS_ON
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.