views:

365

answers:

1

I am working on an application that requires text larger than the viewable screen size in both a TreeField and a ListField. As you know, the TreeField and ListField callbacks support only graphics.drawText() methods, so I cannot add an instance of a Field per row.

Does anyone have a method of Scrolling horizontally past the viewable text size?

Is there maybe a scrollable panel that would work? I know of the NullField(Field.Focusable) trick but this won't work on the list field.

Lastly, I am aware that the type of screen makes a different as FullScreen and MainScreen use VerticalFieldMangers. So am using a PopupScreen at the moment for my testing.

Thank you in advance for your time.

A: 

Maybe it's better to split text in two lines and set row height 2 x font height (+ margins)?

alt text

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;
    }
}
Max Gontar
You may be right about this, it doesn't seem possible any other way. I was thinking perhaps if I could just show the second line on one that is focused it would help stop from cluttering the screen.
sethxian
well, you can If you build a custom control (vertical manager + labels)... Row heigh in ListField is same for all rows ((
Max Gontar