Java Utililty Methods Draw String

List of utility methods to do Draw String

Description

The list of methods to do Draw String are organized into topic(s).

Method

voiddrawString(final Graphics g, final String text, final int x, final int y)
Paints string.
g.drawString(text, x, y);
voiddrawString(Graphics g, String s, int alignment, Rectangle r)
Draws a string into a Graphics object.
if (s == null)
    return;
int x = r.x;
if ((alignment & CENTER) != 0) {
    x += (r.width - g.getFontMetrics().stringWidth(s)) / 2;
} else if ((alignment & RIGHT) != 0) {
    x += r.width - g.getFontMetrics().stringWidth(s);
g.drawString(s, x, r.y);
intdrawString(Graphics g, String s, int x, int y, int width, int height)
Draws a string starting at coordinate x,y and try to fit it in the given width and height.
return drawString(g, s, x, y, width, height, true);
voiddrawString(Graphics g, String s, int x, int y, int width, int height)
draw String
FontMetrics fm = g.getFontMetrics();
int lineHeight = fm.getHeight();
int textHeight = 0;
int curX = x;
int curY = y;
String[] words = s.split(" ");
for (String word : words) {
    int wordWidth = fm.stringWidth(word + " ");
...
voiddrawString(Graphics g, String text, int underlinedChar, int x, int y)
draw String
g.drawString(text, x, y);
voiddrawString(Graphics g, String text, int underlinedChar, int x, int y)
Draw a string with the graphics g at location (x,y) just like g.drawString() would.
char lc, uc;
int index = -1, lci, uci;
if (underlinedChar != '\0') {
    uc = Character.toUpperCase((char) underlinedChar);
    lc = Character.toLowerCase((char) underlinedChar);
    uci = text.indexOf(uc);
    lci = text.indexOf(lc);
    if (uci == -1)
...
voiddrawString(Graphics g, String text, int underlinedChar, int x, int y)
Draws a String at the given location, underlining the first occurence of a specified character.
int index = -1;
if ((underlinedChar >= 0) || (underlinedChar <= 0xffff))
    index = text.toLowerCase().indexOf(Character.toLowerCase((char) underlinedChar));
drawStringUnderlineCharAt(g, text, index, x, y);
voiddrawString(Graphics g, String text, int x, int y)
draw String
for (String line : text.split("\n"))
    g.drawString(line, x, y += g.getFontMetrics().getHeight());
voiddrawString(Graphics g2, String string, int x, int y, Font font, Color color)
Draw a string.
Color oldColor = g2.getColor();
g2.setColor(color);
drawString(g2, string, x, y, font);
g2.setColor(oldColor);
voiddrawString(Graphics2D g, String s, int x, int y, int width)
draw String
FontMetrics fm = g.getFontMetrics();
int lineHeight = fm.getHeight();
int curX = x;
int curY = y;
String[] words = s.split(" ");
for (String word : words) {
    int wordWidth = fm.stringWidth(word + " ");
    if (curX + wordWidth >= x + width) {
...