VerticalFieldManager不为jre5滚动

时间:2012-01-05 11:53:31

标签: blackberry

我在我的系统中使用jre 5和9550模拟器..我的应用程序中有一个问题,滚动VerticalFieldManager ..

我正在从我的MainScreen java文件中调用一个新的屏幕..

守则就像......

UiApplication.getUiApplication().invokeLater(new Runnable() 
{
    public void run() 
    {
        try
        {
            UiApplication.getUiApplication().pushScreen(new CustomDialog());
        }
        catch (Exception e) {
            Dialog.alert("loading Error");
        }
    }
});

而且CustomDialog.java就像......

public final class CustomDialog extends MainScreen
{
    LabelField title, message;
    HorizontalFieldManager hfm;
    VerticalFieldManager vfm;
    GridFieldManager gfm;

    public CustomDialog()
    {
        super(Screen.DEFAULT_CLOSE);

        hfm = new HorizontalFieldManager(Field.FIELD_LEFT);
        title = new LabelField("hello User",FIELD_HCENTER)
        {
            protected void paint(Graphics graphics) {
                graphics.setColor(Color.BROWN);
                super.paint(graphics);
            };
        };
        title.setFont(getFont().derive(Font.BOLD, 20));
        hfm.add(title);
        add(hfm);

        vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
        message = new LabelField("my text");//Actually a long text..
        vfm.add(message);
        VerticalFieldManager tmp = new VerticalFieldManager();
        tmp.add(vfm);
        add(tmp);
    }
}

消息显示在屏幕上,但不滚动.. 实际上,该消息是一个长文本,我想滚动VerticalFieldManager ..

如何让它滚动?

3 个答案:

答案 0 :(得分:1)

要获得VerticalFieldManager滚动,请在NullField之前和之后添加可聚焦LabelField对象。

vfm.add(New NullField());
vfm.add(message);
vfm.add(New NullField());

现在它将立即从标签的底部滚动到顶部,反之亦然。要解决此问题,请使用RichTextField。它是显示长文本的最佳选择。它本身处理垂直(逐行)和水平(逐个字符)滚动。

答案 1 :(得分:0)

如果文字不太长,Rupaks的答案将适用于滚动。但是如果文本像几个页面,例如EULA或条款和条件,它将从起始页面跳到最后一页。

您可以使用以下代码解决这个问题,我已经用editField替换了labelField。

                    LabelField title;
                    EditField message;
                    HorizontalFieldManager hfm;
                    VerticalFieldManager vfm;
                    GridFieldManager gfm; 
                    final MainScreen screen=new MainScreen();
                    hfm = new HorizontalFieldManager(Field.FIELD_LEFT);
                    title = new LabelField("hello User",FIELD_HCENTER)
                    {
                        protected void paint(Graphics graphics) {
                            graphics.setColor(Color.BROWN);
                            super.paint(graphics);
                        };
                    };
                    title.setFont(getFont().derive(Font.BOLD, 20));
                    hfm.add(title);
                    add(hfm);

                    vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
                    message = new EditField("","long text");

                    vfm.add(message);
                    VerticalFieldManager tmp = new VerticalFieldManager();
                    tmp.add(vfm);
                    add(tmp); 

答案 2 :(得分:0)

尝试

    super(Screen.DEFAULT_CLOSE|VERTICAL_SCROLL);

isteadOf

    super(Screen.DEFAULT_CLOSE);

    vfm = new VerticalFieldManager(VERTICAL_SCROLL);

isteadOf

    vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);