|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--waba.fx.FontMetrics
FontMetrics computes font metrics including string width and height.
FontMetrics are usually used to obtain information about the widths and heights of characters and strings when drawing text on a surface.
Here is an example that uses FontMetrics to get the width of a string:
...
Font font = Font.getFont("Tiny", true, Font.BIG_SIZE);
FontMetrics fm = font.fm;
String s = "This is a line of text.";
int stringWidth = fm.getTextWidth(s);
...
| Field Summary | |
int |
ascent
READ-ONLY member: indicates the average height of this font from the baseline to up. |
int |
descent
READ-ONLY member: indicates the average height of this font from the baseline to down. |
protected Font |
font
|
int |
height
READ-ONLY member: total height of this font (ascent+descent). |
int |
leading
READ-ONLY member: distance between two lines of text |
| Constructor Summary | |
FontMetrics(Font font)
Deprecated. Don't use this constructor; access the myFont.fm member instead. |
|
| Method Summary | |
int |
getCharWidth(char c)
Returns the width of the given character in pixels. |
int |
getMaxWidth(java.lang.String[] names,
int start,
int count)
Returns the maximum text width from the given list of names. |
int |
getTextWidth(char[] chars,
int start,
int count)
Returns the width of the given text in pixels. |
int |
getTextWidth(java.lang.String s)
Returns the width of the given text string in pixels. |
int |
stringWidth(java.lang.String s)
Calls getTextWidth, just provided to be more compatible with JDK. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected Font font
public int ascent
public int descent
public int leading
public int height
| Constructor Detail |
public FontMetrics(Font font)
myFont.fm member instead.
| Method Detail |
public int getCharWidth(char c)
public int getTextWidth(java.lang.String s)
public int stringWidth(java.lang.String s)
public int getTextWidth(char[] chars,
int start,
int count)
chars - the text character arraystart - the start position in arraycount - the number of characters
public int getMaxWidth(java.lang.String[] names,
int start,
int count)
String []labels = {"Name","Age","Address"};
int xx = this.fm.getMaxWidth(labels, 0, labels.length);
add(new Label(labels[0]), LEFT, AFTER);
add(edName = new Edti(""),xx, SAME);
...
start - The starting indexcount - The number of elements to check.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||