public final class FontMetrics
extends java.lang.Object
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.stringWidth(s); ...
Modifier and Type | Field and Description |
---|---|
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).
|
Modifier and Type | Method and Description |
---|---|
int |
charWidth(char c)
Returns the width in pixels of the given character.
|
int |
charWidth(java.lang.StringBuffer s,
int i)
Returns the width in pixels of the char located at the given index in the StringBuffer.
|
int |
getMaxWidth(java.lang.String[] names,
int start,
int count)
Returns the maximum text width from the given list of names.
|
int |
sbWidth(java.lang.StringBuffer s)
Returns the width in pixels of the given StringBuffer.
|
int |
sbWidth(java.lang.StringBuffer s,
int start,
int count)
Returns the width in pixels of the given StringBuffer range.
|
int |
stringWidth(char[] chars,
int start,
int count)
Returns the width in pixels of the given char array range.
|
int |
stringWidth(java.lang.String s)
Returns the width in pixels of the given text string.
|
protected Font font
public int ascent
public int descent
public int height
public int charWidth(char c)
public int stringWidth(java.lang.String s)
public int stringWidth(char[] chars, int start, int count)
chars
- the text character arraystart
- the start position in arraycount
- the number of characterspublic 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 Edit(""),xx, SAME); ...
start
- The starting indexcount
- The number of elements to check.public int sbWidth(java.lang.StringBuffer s)
public int sbWidth(java.lang.StringBuffer s, int start, int count)
public int charWidth(java.lang.StringBuffer s, int i)