Skip to main content

ask: scroll down to last added component

2 replies [Last post]
Anonymous

Hi All,

This may sound stupid.
I have form that contains many component. I need the scrollbarY scrolls down
everytime I add new componet to the form, so the last added component can
fully visible. Please see my code below. How can I do that? Can someone
point me to complete tutorial or documentation related my problem?

Thanks id advance.
Best Regards
Gultor

private class TestForm extends Form implements ActionListener {

private Command cmdAdd = new Command("Add");
private Command cmdClear = new Command("Clear");

public TestForm() {
addCommand(cmdClear);
addCommand(cmdAdd);
setScrollableY(true);
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
addCommandListener(this);
setFocusScrolling(true);
show();
}

public void actionPerformed(ActionEvent evt) {
Command cmd = evt.getCommand();
if (cmd == cmdClear) {
removeAll();
repaint();
} else if (cmd == cmdAdd) {
Label lx = new Label("This is label");
lx.setFocusable(true);
addComponent(lx);
if (lx.hasFocus()) {
lx.requestFocus();
}
repaint();
}
}
}
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mixa

I think you can use Form.scrollComponentToVisible() for that.

IMHO calling show() in a constructor is not good from code style point
of view (though it should work). Just developers usually do not expect
any control handling actions in constructors, preferable only
initializations. But it's a test form, so you probably know what
you're doing ))

Regards, Mike
[code]
/* ----------------------
* J2ME consulting/development:
* gmixaz[@]gmail[.]com ICQ 50059348
*/
[/code]

On Wed, Jul 7, 2010 at 9:40 AM, Arvian Fr wrote:
> Hi All,
>
> This may sound stupid.
> I have form that contains many component. I need the scrollbarY scrolls down
> everytime I add new componet to the form, so the last added component can
> fully visible. Please see my code below. How can I do that? Can someone
> point me to complete tutorial or documentation related my problem?
>
> Thanks id advance.
> Best Regards
> Gultor
>
>
> private class TestForm extends Form implements ActionListener {
>
>         private Command cmdAdd = new Command("Add");
>         private Command cmdClear = new Command("Clear");
>
>         public TestForm() {
>             addCommand(cmdClear);
>             addCommand(cmdAdd);
>             setScrollableY(true);
>             setLayout(new BoxLayout(BoxLayout.Y_AXIS));
>             addCommandListener(this);
>             setFocusScrolling(true);
>             show();
>         }
>
>         public void actionPerformed(ActionEvent evt) {
>             Command cmd = evt.getCommand();
>             if (cmd == cmdClear) {
>                 removeAll();
>                 repaint();
>             } else if (cmd == cmdAdd) {
>                 Label lx = new Label("This is label");
>                 lx.setFocusable(true);
>                 addComponent(lx);
>                 if (lx.hasFocus()) {
>                     lx.requestFocus();
>                 }
>                 repaint();
>             }
>         }
>     }
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

Arvian Fr

Thanks Mike, starting from your hint and little googling, now my code works
just fine :)

On Wed, Jul 7, 2010 at 4:22 PM, Mixa wrote:

> I think you can use Form.scrollComponentToVisible() for that.
>
> IMHO calling show() in a constructor is not good from code style point
> of view (though it should work). Just developers usually do not expect
> any control handling actions in constructors, preferable only
> initializations. But it's a test form, so you probably know what
> you're doing ))
>
> Regards, Mike
> [code]
> /* ----------------------
> * J2ME consulting/development:
> * gmixaz[@]gmail[.]com ICQ 50059348
> */
> [/code]
>
> On Wed, Jul 7, 2010 at 9:40 AM, Arvian Fr wrote:
> > Hi All,
> >
> > This may sound stupid.
> > I have form that contains many component. I need the scrollbarY scrolls
> down
> > everytime I add new componet to the form, so the last added component can
> > fully visible. Please see my code below. How can I do that? Can someone
> > point me to complete tutorial or documentation related my problem?
> >
> > Thanks id advance.
> > Best Regards
> > Gultor
> >
> >
> > private class TestForm extends Form implements ActionListener {
> >
> > private Command cmdAdd = new Command("Add");
> > private Command cmdClear = new Command("Clear");
> >
> > public TestForm() {
> > addCommand(cmdClear);
> > addCommand(cmdAdd);
> > setScrollableY(true);
> > setLayout(new BoxLayout(BoxLayout.Y_AXIS));
> > addCommandListener(this);
> > setFocusScrolling(true);
> > show();
> > }
> >
> > public void actionPerformed(ActionEvent evt) {
> > Command cmd = evt.getCommand();
> > if (cmd == cmdClear) {
> > removeAll();
> > repaint();
> > } else if (cmd == cmdAdd) {
> > Label lx = new Label("This is label");
> > lx.setFocusable(true);
> > addComponent(lx);
> > if (lx.hasFocus()) {
> > lx.requestFocus();
> > }
> > repaint();
> > }
> > }
> > }
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
Best Regards,
Arvian Fr
[att1.html]