Example usage for java.awt Graphics drawString

List of usage examples for java.awt Graphics drawString

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Draws the given <code>String</code>, centered at <code>(x,y)</code>, using
 * the given graphics context.//from  w  ww. j av a  2  s  .c  om
 * 
 * @param s the string
 * @param g the graphics context to draw in
 * @param x the x coordinate for center of the <code>String</code>
 * @param y the y coordinate for center of the <code>String</code>
 */
public static void drawCenteredString(String s, Graphics g, int x, int y) {
    ((Graphics2D) g).addRenderingHints(hints);

    FontMetrics fm = g.getFontMetrics();
    int ht = fm.getAscent() + fm.getDescent();
    int width = fm.stringWidth(s);
    g.drawString(s, x - width / 2, y + (fm.getAscent() - ht / 2));
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

private static void drawHelp(final Graphics g) {
    final int x = (int) (g.getClipBounds().getWidth() / 2);
    final int y = (int) (g.getClipBounds().getHeight() / 2);

    final FontMetrics metrics = g.getFontMetrics();
    final String name = "Right click here to add an operator";
    final Rectangle2D rect = metrics.getStringBounds(name, g);
    final int stringWidth = (int) rect.getWidth();

    g.setColor(Color.black);/*from   w  ww  .  ja v a2 s .c  o  m*/
    g.drawString(name, x - stringWidth / 2, y);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getColor() + "", 10, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getFont() + "", 10, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getClipRect() + "", 10, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getClip() + "", 10, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.toString() + "", 10, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getClipBounds() + "", 10, 30);
}

From source file:MyCanvas.java

public void paint(Graphics g) {
    g.drawString(Long.toString(System.currentTimeMillis()), 10, 30);
    repaint(1000);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.drawString(g.getClipBounds().toString(), 10, 30);

    g.clipRect(10, 40, getSize().width - 20, getSize().height - 80);

    g.fillOval(0, 0, getSize().width, getSize().height);

    String newClip = g.getClipBounds().toString();

    g.setClip(0, 0, getSize().width, getSize().height);

    g.drawString(newClip, 10, getSize().height - 10);
}