I have extended the TextList widget with linewrapping methods. What do you think?
It still remains to break words that don't fit on one line by themselves.
public java.util.List<Label> addItemLineWrap(String text)
{
return this.addItemLineWrap(text, null, null);
}
public java.util.List<Label> addItemLineWrap(String text, Font font)
{
return this.addItemLineWrap(text, null, font);
}
public java.util.List<Label> addItemLineWrap(String text, Colorf color)
{
return this.addItemLineWrap(text, color, null);
}
public java.util.List<Label> addItemLineWrap(String text, Colorf color, Font font)
{
java.util.List<Label> labels = new ArrayList<Label>();
Scanner scanner = new Scanner(text);
StringBuffer line = new StringBuffer();
Label label = addItem("", font, color);
Dim2f dim = new Dim2f();
while (scanner.hasNext())
{
String word = scanner.next();
if (scanner.hasNext())
{
word = word + " ";
}
label.setText(line.toString() + word);
label.getMinimalSize(dim);
if (dim.getWidth() > this.getWidth() - 20)
{
label.setText(line.toString());
line.delete(0, line.length());
label = addItem(word, font, color);
}
line.append(word);
}
return labels;
}