Maybe it's better to split text in two lines and set row height 2 x font height (+ margins)?
class Scr extends MainScreen implements ListFieldCallback {
int DISPLAY_WIDTH = Display.getWidth();
Vector mItems = new Vector();
ListField mListField = new ListField();
public Scr() {
mListField.setCallback(this);
add(mListField);
mItems.addElement("Lorem ipsum dolor sit amet, ");
mItems.addElement("Lorem ipsum dolor sit");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit, sed diam "+
"nonummy nibh euismod");
mItems.addElement("Lorem ipsum dolor sit amet, "+
"consectetuer adipiscing elit");
mItems.addElement("Lorem ipsum dolor sit amet, ");
mListField.setSize(mItems.size());
mListField.setRowHeight(
mListField.getFont().getHeight()*2 + 4);
}
public void drawListRow(ListField field, Graphics g,
int i, int y, int w) {
// Draw the text.
String text = (String) get(field, i);
if(g.getFont().getAdvance(text) > w)
{
int index = 0;
while(g.getFont().getAdvance(text.substring(0, index)) < w)
{
index++;
}
g.drawText(text.substring(0, index), 0, y, 0, w);
g.drawText(text.substring(index, text.length()-1), 0,
y + g.getFont().getHeight()+ 4, DrawStyle.ELLIPSIS, w);
}
else
{
g.drawText(text, 0, y, 0, w);
}
}
public Object get(ListField listField, int index) {
return mItems.elementAt(index);
}
public int getPreferredWidth(ListField listField) {
return DISPLAY_WIDTH;
}
public int indexOfList(ListField listField,
String prefix, int start) {
return 0;
}
}