List of utility methods to do Font Text Width
List | wrap(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; |
void | wrapLineInto(String line, List 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) ... |