Java Utililty Methods Draw String

List of utility methods to do Draw String

  1. HOME
  2. Java
  3. D
  4. Draw String

Description

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

Method

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 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 + " ");
...
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(Graphics g, String text, int x, int y)
draw String
for (String line : text.split("\n"))
 g.drawString(line, x, y += g.getFontMetrics().getHeight());
void drawString(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);
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) {
...


AltStyle によって変換されたページ (->オリジナル) /