Java Utililty Methods Font Text Width

List of utility methods to do Font Text Width

Description

The list of methods to do Font Text Width are organized into topic(s).

Method

Listwrap(String str, FontMetrics fm, int maxWidth)
Returns an array of strings, one for each line in the string after it has been wrapped to fit lines of maxWidth.
List<String> lines = splitIntoLines(str);
if (lines.size() == 0)
    return lines;
ArrayList<String> strings = new ArrayList<String>();
for (String line : lines)
    wrapLineInto(line, strings, fm, maxWidth);
return strings;
voidwrapLineInto(String line, List list, FontMetrics fm, int maxWidth)
Given a line of text and font metrics information, wrap the line and add the new line(s) to list.
int len = line.length();
int width;
while (len > 0 && (width = fm.stringWidth(line)) > maxWidth) {
    int guess = len * maxWidth / width;
    String before = line.substring(0, guess).trim();
    width = fm.stringWidth(before);
    int pos;
    if (width > maxWidth) 
...