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

public void paint(Graphics g) {
    g.setFont(new Font("SansSerif", Font.BOLD, 12));
    FontMetrics fm = g.getFontMetrics();
    g.drawString("Current font: " + g.getFont(), 10, 40);
    g.drawString("Ascent: " + fm.getAscent(), 10, 55);
    g.drawString("Descent: " + fm.getDescent(), 10, 70);
    g.drawString("Height: " + fm.getHeight(), 10, 85);
    g.drawString("Leading: " + fm.getLeading(), 10, 100);

    Font font = new Font("Serif", Font.ITALIC, 14);
    fm = g.getFontMetrics(font);//w  ww .j  a  v  a2s  .c  o m
    g.setFont(font);
    g.drawString("Current font: " + font, 10, 130);
    g.drawString("Ascent: " + fm.getAscent(), 10, 145);
    g.drawString("Descent: " + fm.getDescent(), 10, 160);
    g.drawString("Height: " + fm.getHeight(), 10, 175);
    g.drawString("Leading: " + fm.getLeading(), 10, 190);
}

From source file:ColorScribble.java

public void paint(Graphics g) {
    g.setColor(getForeground());
    g.drawString("Parameter", 10, 10);

}

From source file:Main.java

License:asdf

public void paint(Graphics g, JComponent c) {
    FontMetrics metrics = c.getFontMetrics(g.getFont());
    g.setColor(c.getForeground());/* www.  j  a  va  2s . co  m*/
    g.drawString(((JToolTip) c).getTipText(), 1, 1);
    g.drawImage(new ImageIcon("yourImage").getImage(), 1, metrics.getHeight(), c);
}

From source file:Main.java

public void paint(Graphics g) {
    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.BOLD, fontSize));

    String s = "www.java2s.com";

    g.setColor(Color.black);//from  www  .  j a  v  a  2 s.c  o m
    g.drawString(s, 30, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize));

    String s = "www.java2s.com";

    g.setColor(Color.black);//from   w w  w.j  a  v  a2  s .c o  m
    g.drawString(s, 30, 30);
}

From source file:painting.SwingPaintDemo4.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawString("This is my custom Panel!", 10, 20);

    redSquare.paintSquare(g);/*from  w ww  . j a  v a2 s. co  m*/
}

From source file:Main.java

public void paint(Graphics g) {
    int fontSize = 20;

    g.setFont(new Font("TimesRoman", Font.ITALIC, fontSize));

    String s = "www.java2s.com";

    g.setColor(Color.black);/*from w  w w .  j  ava  2s .  c om*/
    g.drawString(s, 30, 30);
}

From source file:Main.java

public void paint(Graphics g) {
    v = g.getFontMetrics(getFont()).getHeight() + 1;
    int j = 0;/*from   ww w  .j  a v a 2  s .c  o m*/
    int k = s.length();
    while (j < k + 1) {
        if (j == k)
            g.drawString(s.substring(j), 10, 10 + (j * v));
        else
            g.drawString(s.substring(j, j + 1), 10, 10 + (j * v));
        j++;
    }
}

From source file:WalkingText.java

/** Paint is called by Applet to redraw the screen */
public void paint(Graphics g) {
    g.drawString(mesg, xloc, yloc);
    // if ((xloc + textWidth) > getSize().width) {
    //    int negLoc = textWidth-(width-xloc);
    //    System.out.println("xloc, textWidth, negLoc: " + xloc + "," +
    //          textWidth + ", " + negLoc);
    //    g.drawString(mesg, negLoc, yloc);
    // }/*from w w  w.  java2 s .c o  m*/
}

From source file:StreamConverter.java

public void paint(Graphics g) {
    Insets insets = getInsets();/*from   w  w w  . java2 s  . co m*/
    int x = insets.left;
    int y = insets.top;
    g.drawString(outString, x + 6, y + fontM.getAscent() + 14);
}