简体   繁体   English

LWUIT textarea滚动问题

[英]LWUIT textarea scroll issue

I have problem with LWUIT scroll. 我对LWUIT滚动有问题。 I have a form contain textarea and 20 labels. 我有一个包含textarea和20个标签的表格。 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) {
}

} }

You need to disable cyclic focus using the setCyclicFocus method. 您需要使用setCyclicFocus方法禁用循环焦点。

mainForm.setCyclicFocus(false);

EDIT: LWUIT scrolling works based on the focus of the current component. 编辑:LWUIT滚动基于当前组件的焦点工作。 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. 现在,setCyclicFocus应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM