The list of methods to do Draw String are organized into topic(s).
void
drawString(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);
int
drawString(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);
void
drawString(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)
...
void
drawString(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);
void
drawString(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) {
...