Example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON.

Prototype

Object VALUE_ANTIALIAS_ON

To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.

Click Source Link

Document

Antialiasing hint value -- rendering is done with antialiasing.

Usage

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "\"www.java2s.com,\" www.java2s.com";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);
    as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 22);
    g2.drawString(as.getIterator(), 24, 70);

}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "\"www.java2s.com,\" www.java2s.com";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);
    as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 11);
    g2.drawString(as.getIterator(), 24, 70);

}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "\"www.java2s.com,\" www.java2s.com";

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, plainFont);

    g2.drawString(as.getIterator(), 24, 70);

}

From source file:EllipseRenderHints.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape s = new Ellipse2D.Float(20, 50, 250, 150);
    g2.setPaint(Color.BLACK);//from w  w w  .ja  va  2s.  c o  m
    g2.draw(s);
}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font font = new Font("Serif", Font.PLAIN, 72);
    g2.setFont(font);//from ww w  .ja va  2  s.  c  om

    String s = "www.java2s.com";
    float x = 50, y = 150;

    FontRenderContext frc = g2.getFontRenderContext();
    float width = (float) font.getStringBounds(s, frc).getWidth();
    Line2D baseline = new Line2D.Float(x, y, x + width, y);
    g2.setPaint(Color.lightGray);
    g2.draw(baseline);

    // Draw the ascent.
    LineMetrics lm = font.getLineMetrics(s, frc);
    Line2D ascent = new Line2D.Float(x, y - lm.getAscent(), x + width, y - lm.getAscent());
    g2.draw(ascent);

    // Draw the descent.
    Line2D descent = new Line2D.Float(x, y + lm.getDescent(), x + width, y + lm.getDescent());
    g2.draw(descent);

    // Draw the leading.
    Line2D leading = new Line2D.Float(x, y + lm.getDescent() + lm.getLeading(), x + width,
            y + lm.getDescent() + lm.getLeading());
    g2.draw(leading);

    // Render the string.
    g2.setPaint(Color.black);
    g2.drawString(s, x, y);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//from  w w  w  .  ja  va 2 s  .c om

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);/* w  ww.j  a v a 2  s .  c o  m*/

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getFont());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//ww w  . ja  v a  2  s.c  o  m

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getOutline());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);/*from  w  w  w  .java 2  s. c o  m*/

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getVisualBounds());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//from   w  w w .  ja v  a 2  s.c  om

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getLogicalBounds());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}