1

使用 LWUIT,我有Form两个组件:一个只读TextArea和一个Button

TextArea text = new TextArea("blah blah blah blah blah blah blah blah blah ...");
text.setEditable(false);
form.addComponent(text);

Button button = new Button("Press Me !");
button.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent evt) {
          // DESIRED CODE IS HERE ...
     }
});
form.addComponent(button);

TextArea一个Scrollbar因为它包含一个long String,当用户向下移动DOWN'TextArea直到Scrollbar它到达末尾时String,然后将Button焦点留TextAreaScrollbar末尾TextArea

我希望,当Button单击 时,滚动条返回到其原始状态,TopTextArea不是在BottomTextArea我怎么能这样做?

4

1 回答 1

2

对于感兴趣的人,这里是解决方案。
通过使用自定义 TextArea

public class CustomTextArea extends TextArea {
    public TextAreaScrollControlled(String text) {
        super(text);
    }

    public void resetScrollBackToTop() {
        setScrollY(0);
    }
}

然后代码如下(而不是问题中发布的代码):

CustomTextArea text = new CustomTextArea("blah blah blah blah blah blah ...");
text.setEditable(false);
addComponent(text);

Button button = new Button("Press Me !");
button.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent evt) {
          text.resetScrollBackToTop(); // SOLUTION
     }
});
form.addComponent(button);

PS。“文本”应该是最终的或类的成员;)

于 2012-01-02T16:43:36.430 回答