Question

I have problem with LWUIT scroll. I have a form contain textarea and 20 labels. When it scroll to the bottom, it jump to the top (like cycle). Sorry for my bad english :(

This is my code

public class ScrollMidlet extends MIDlet {

public void startApp() {
    Display.init(this);
    Form mainForm = new Form("Scroll issue");
    mainForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

    TextArea textArea = new TextArea("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum");
    mainForm.addComponent(textArea);

    for (int i = 0; i < 20; i++) {
        mainForm.addComponent(new Label("This is label " + (i + 1)));
    }
    mainForm.setScrollable(true);
    mainForm.show();
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

}

Was it helpful?

Solution

You need to disable cyclic focus using the setCyclicFocus method.

mainForm.setCyclicFocus(false);

EDIT: LWUIT scrolling works based on the focus of the current component. So when you press the down arrow, the focus changes to the element below and, if necessary, the Form scrolls. Labels are not focusable by default, so they won't receive focus and the scrolling will not work correctly. To correct this you should modify the label creation.

Label l = new Label("This is label " + (i + 1));
l.setFocusable(true);
mainForm.addComponent(l);

Also, it is really bad user experience to scroll horizontally to read content, so you should forbid horizontal scrolling.

mainForm.setScrollableX(false);
mainForm.setScrollableY(true);

Now setCyclicFocus should work without problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top