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:GeneralPathDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*w  w w.  j  a  va  2s  . com*/
    int x = 5;
    int y = 7;

    // draw GeneralPath (polygon)
    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    polygon.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        polygon.lineTo(xPoints[index], yPoints[index]);
    }
    polygon.closePath();

    g2.draw(polygon);
    g2.drawString("GeneralPath", x, 250);

}

From source file:FilledGeneralPath.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int x = 5;/* w  ww . j  ava  2  s . co m*/
    int y = 7;

    // fill and stroke GeneralPath
    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath filledPolygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    filledPolygon.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        filledPolygon.lineTo(xPoints[index], yPoints[index]);
    }
    filledPolygon.closePath();
    g2.setPaint(Color.red);
    g2.fill(filledPolygon);
    g2.setPaint(Color.black);
    g2.draw(filledPolygon);
    g2.drawString("Filled and Stroked GeneralPath", x, 250);
}

From source file:GeneralPathOpenDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*from  www.  j  av  a2 s .c om*/
    int x = 5;
    int y = 7;

    // draw GeneralPath (polyline)

    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    polyline.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        polyline.lineTo(xPoints[index], yPoints[index]);
    }

    g2.draw(polyline);
    g2.drawString("GeneralPath (open)", x, 250);
}

From source file:TextHitInfoDemo.java

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

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

    String s = "Java Source and Support";
    Font font = new Font("Serif", Font.PLAIN, 32);

    if (mTextLayout == null) {
        FontRenderContext frc = g2.getFontRenderContext();
        mTextLayout = new TextLayout(s, font, frc);
    }/*  www. j  a  v a2  s .  co m*/

    mTextLayout.draw(g2, mX, mY);
}

From source file:MainClass.java

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

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

    g2.setPaint(Color.black);/*from w  w  w.  j  ava2 s . co m*/
    g2.draw(shape);
}

From source file:MainClass.java

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font serifFont = new Font("Serif", Font.PLAIN, 32);

    AttributedString as = new AttributedString("www.java2s.com");
    as.addAttribute(TextAttribute.FONT, serifFont);

    Image image = createImage();/*  ww  w .  j a  v a 2 s  .com*/
    ImageGraphicAttribute imageAttribute = new ImageGraphicAttribute(image, GraphicAttribute.TOP_ALIGNMENT);
    as.addAttribute(TextAttribute.CHAR_REPLACEMENT, imageAttribute, 5, 6);

    g2.drawString(as.getIterator(), 20, 120);

}

From source file:ArcDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);//from  w w w  .ja va  2 s . c  o m
    int x = 5;
    int y = 7;

    g2.setStroke(wideStroke);
    g2.draw(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN));
    g2.drawString("Arc2D", x, 250);
}

From source file:EllipseDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*from  w  w  w. j a  v a  2s .  c o m*/
    int x = 5;
    int y = 7;

    g2.setStroke(stroke);
    g2.draw(new Ellipse2D.Double(x, y, 200, 200));
    g2.drawString("Ellipse2D", x, 250);

}

From source file:RectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*  w  ww  .ja  v  a2s .  com*/
    int x = 5;
    int y = 7;

    g2.setStroke(stroke);
    g2.draw(new Rectangle2D.Double(x, y, 200, 200));
    g2.drawString("Rectangle2D", x, 250);

}

From source file:MainClass.java

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

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

    g2.setPaint(Color.black);/*  www. j ava2 s .  co  m*/
    g2.draw(shape);

    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);

    g2.setPaint(Color.red);
    g2.draw(shape);

}