Example usage for java.awt Graphics2D drawString

List of usage examples for java.awt Graphics2D drawString

Introduction

In this page you can find the example usage for java.awt Graphics2D drawString.

Prototype

public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);

Source Link

Document

Renders the text of the specified iterator applying its attributes in accordance with the specification of the TextAttribute class.

Usage

From source file:Main.java

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

    AttributedString as1 = new AttributedString("1234567890");
    as1.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 3, 4);
    g2d.drawString(as1.getIterator(), 15, 60);
}

From source file:LineDemo2D.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 v a2  s  .c  om
    int x = 5;
    int y = 7;

    g2.draw(new Line2D.Double(x, y, 200, 200));
    g2.drawString("Line2D", x, 250);

}

From source file:Main.java

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

    AttributedString as1 = new AttributedString("1234567890");
    as1.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 2, 8);
    g2d.drawString(as1.getIterator(), 15, 60);
}

From source file:TextAttributesSuperscript.java

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

    AttributedString as1 = new AttributedString("1234567890");
    as1.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 5, 7);
    g2d.drawString(as1.getIterator(), 15, 60);
}

From source file:Main.java

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

    Font font = new Font("Serif", Font.PLAIN, 40);

    AttributedString as1 = new AttributedString("1234567890");
    as1.addAttribute(TextAttribute.FONT, font);
    g2d.drawString(as1.getIterator(), 15, 60);
}

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  a2  s  .c om
    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);//from   w ww.j  ava2 s . 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:TextQualityDemoVALUE_TEXT_ANTIALIAS_LCD_HBGR.java

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

    g2.setColor(Color.WHITE);//from  w ww.j ava2 s .co  m
    g2.fillRect(0, 0, d.width, d.height);

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

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

    g2.drawString("abcdefghijklmnopqrstuvwxyz", 20, 40);
    g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 20, 60);
    g2.drawString("1234567890-=!@#$%^&*()_+,./<>?", 20, 80);

    g.drawImage(backBuffer, 0, 0, this);
}

From source file:StringGraidentPaint.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    g2D.setFont(font);/*w  w w  .  j a v a 2  s .  c om*/
    GradientPaint gp = new GradientPaint(30.0f, 50.0f, Color.blue, fontMetrics.stringWidth("Hello!"),
            fontMetrics.getHeight(), Color.red);
    g2D.setPaint(gp);
    g2D.drawString("Hello!", 20, 200);

}

From source file:pt.lsts.neptus.console.plugins.ImageLayers.java

@Override
public void paint(Graphics2D g, StateRenderer2D renderer) {
    g.setColor(Color.orange);/*ww  w.jav a 2  s  .  c  o  m*/
    g.drawString(note, 50, 20);
    for (ImageLayer il : layers)
        il.paint((Graphics2D) g.create(), renderer);
}