How to automate scroll up in container

55 views
Skip to first unread message

enu...@gmail.com

unread,
Aug 4, 2014, 7:08:05 PM8/4/14
to codenameone...@googlegroups.com
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA
Desktop OS: Windows
Simulator: YES
Device: N/A

Hi Guys,

Please quick help. I want my chat application to scroll to the latest message label.

Currently as new labels are added, they are hidden at the bottom unless the container is scrolled up.

I would like to automatically scroll up when the container is full to the bottom.

My research shows that scrollComponentToVisible() should work but it doesn't.

Here is my simple test code.

protected void onMain_BtnAddAction(final Component c, ActionEvent event){
       
Label l = new Label();
        l
.setName("label"+count);
        l
.setText("New Label"+count);
       
        findMainContainer
(c.getComponentForm()).addComponent(l);
        findMainContainer
(c.getComponentForm()).scrollComponentToVisible(l);
        c
.getComponentForm().revalidate();
       
        count
++;
       
   
}

On clicking the button, a new label is added to a Container with BoxLayout Y (set to scrollable on Y axis).

Help is much appreciated.


Shai Almog

unread,
Aug 5, 2014, 1:30:30 AM8/5/14
to codenameone...@googlegroups.com, enu...@gmail.com
Place the revaidate first and the scroll next.

enu...@gmail.com

unread,
Aug 5, 2014, 9:36:01 PM8/5/14
to codenameone...@googlegroups.com, enu...@gmail.com
Thanks Shai, worked like a charm! :)
Reply all
Reply to author
Forward
0 new messages