Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
ykuznetsov
Posts: 9
Registered: ‎09-21-2010
My Device: 9700
Accepted Solution

setScrollPosition(int position) doesn't work

Hi all!!!

I have some problems loading MyTextField with some text.

In onDisplay() method I use setScrollPosition(4000), but it works only if I call Dialog.alert("some message"), if I don't use Dialog before - it sets scroll position only on two screens it's 600px about, Please can anyone tell me what should I do to get it work?

Here is the cod:

 

class MyTextField extends MainScreen {

    protected RichTextField textField;
    protected VerticalFieldManager manager;

    public MyTextField{

        initUi();

    }

 

    public void initUi() {

        manager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL
                    | VerticalFieldManager.VERTICAL_SCROLLBAR);

        String text = "text here can be very long - more than ten screens to scroll with default font size";

        textField = new RichTextField(text, Field.NON_FOCUSABLE);

        manager.add(textField);

        add(manager);

    }

 

    protected void onDisplay() {

        Dialog.alert("some message");

        textField.getManager.setScrollPosition(4000);

    }

}

 

Thanks in advance!!!

 

New Contributor
ykuznetsov
Posts: 9
Registered: ‎09-21-2010
My Device: 9700

Re: setScrollPosition(int position) doesn't work

Please any help!!!

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: setScrollPosition(int position) doesn't work

I would wrap the scroll position in an invokeLater to make sure that the current processing (which will lay the screen out) completes before you try to set the scroll position.  So try something like this:

 

   protected void onDisplay() {

        UiApplication.getUiApplication()invokeLater(new Runnable() {

            public void run() {

                textField.getManager.setScrollPosition(4000);

            }

        });

    }

New Contributor
ykuznetsov
Posts: 9
Registered: ‎09-21-2010
My Device: 9700

Re: setScrollPosition(int position) doesn't work

Thanks a lot!!!

I've already tried this - but it also doesn't work,

now I have solved this using Timer

 

  protected void onDisplay() {
          timer = new Timer();
          long time = 400;
          timer.schedule(new RemindTask(), time);

  }
               

class RemindTask extends TimerTask {
        public void run() {
            MyTextField.getManager().setVerticalScroll(scrollPosition);
            timer.cancel(); //Terminate the timer thread
        }

}