Skip to main content

Scroll a form of consultation

10 replies [Last post]
dunae
Offline
Joined: 2008-06-09
Points: 0

Hello,
I have an application that will be used in non-tactile devices. The problem is that only a form of consulting the scroll does not work for me. What should I do?

Thanks for all.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
danko
Offline
Joined: 2008-07-18
Points: 0

Hi Chen,
I have another case where this solution does not work.
I have a form which uses the scheme label followed by focusable element e.g. button, textfield. If the focus goes from the component at the bottom to the top focusable component the title of that will not be shown.
How can I solve this behavior? After one switch from bottom to top it is impossible to see the first title.

Thanks a lot,
danko

chen

Hi,
You can also control scrolling by using the
Component.scrollRectToVisible(...) or
Container.scrollComponentToVisible(...)
methods.

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> Hi Chen,
> I have another case where this solution does not work.
> I have a form which uses the scheme label followed by focusable element e.g. button, textfield. If the focus goes from the component at the bottom to the top focusable component the title of that will not be shown.
> How can I solve this behavior? After one switch from bottom to top it is impossible to see the first title.
>
> Thanks a lot,
> danko
> [Message sent by forum member 'danko' (danko)]
>
> http://forums.java.net/jive/thread.jspa?messageID=289938
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

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

danko
Offline
Joined: 2008-07-18
Points: 0

Hi,
Thanks for your answer.
I tried to affect the scroll behavior without success and so I wrote a small MIDlet for testing. The scroll behavior on the top is automatically correct but on the bottom it scrolls like my MIDlet at the top. Maybe that behavior is affected because I set the focus to my first focusable component with component.requestFocus().

That is my try which does not work:

import com.sun.lwuit.Button;
import com.sun.lwuit.Component;
import javax.microedition.midlet.*;
import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.events.FocusListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;

public class LwuitTestMidlet extends MIDlet implements ActionListener
{
private Form form;
private Label invisible;

public void startApp()
{
Display.init(this);

form = new Form();
form.setLayout(new BorderLayout());

form.setTitle("LWUIT TestMidlet");
form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

form.addComponent(new Label("asdf asdf"));

Button a = new Button("button");
form.addComponent(a);
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));
form.addComponent(new Label("asdf asdf"));

Button b = new Button("button");
form.addComponent(b);
invisible = new Label();
invisible.setText("qwer qwer");
form.addComponent(invisible);

b.addFocusListener(new FocusListener()
{
public void focusGained(Component arg0)
{
System.out.println("focusGained");
form.scrollComponentToVisible(invisible);
}

public void focusLost(Component arg0)
{
}
});

Command exitCommand = new Command("exit");
form.addCommand(exitCommand);
form.setCommandListener(this);
form.show();
}

public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

public void actionPerformed(ActionEvent ae)
{
System.out.println("actionPerformed");
if (ae.getCommand().getCommandName().equals("exit"))
{
notifyDestroyed();
}
}
}

Thanks for any help,
danko

Shai Almog

Hi Danko,
add the following to your code to workaround this problem:
form.setSmoothScrolling(false);

The issue is that scrolling is animated by default to flow smoothly
in LWUIT, thus you can gain focus before the scroll operation to show
the focused component has completed. So your code actually works but
is overridden by the smooth scrolling feature.

IMO the best workaround for this is to make the label at the bottom
focusable (label.setFocusable(true)).

Thanks.

> Hi,
> Thanks for your answer.
> I tried to affect the scroll behavior without success and so I
> wrote a small MIDlet for testing. The scroll behavior on the top is
> automatically correct but on the bottom it scrolls like my MIDlet
> at the top. Maybe that behavior is affected because I set the focus
> to my first focusable component with component.requestFocus().
>
> http://forums.java.net/jive/thread.jspa?messageID=290582
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

danko
Offline
Joined: 2008-07-18
Points: 0

Hi,

> add the following to your code to workaround this
> problem:
> form.setSmoothScrolling(false);

that works fine!

Thanks a lot,
danko

danko
Offline
Joined: 2008-07-18
Points: 0

Hi Chen,
I don't like this solution.
The reason is that I have a form which one button at the top and a lot of labels. In the majority of cases there is no need to scroll. If I use the bottom label to grab the focus it seems that focus get lost. The user is able to see every component but it seems that there isn't any component focused.

Thanks,
danko

chen

Hi,
Can you please share more details and src sample, not sure what is not
working for you.

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> Hello,
> I have an application that will be used in non-tactile devices. The problem is that only a form of consulting the scroll does not work for me. What should I do?
>
> Thanks for all.
> [Message sent by forum member 'dunae' (dunae)]
>
> http://forums.java.net/jive/thread.jspa?messageID=279070
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

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

dunae
Offline
Joined: 2008-06-09
Points: 0

In fact I think that the problem is not in the source. When I have a lot of labels (severals rows), and if there isn't a button at bottom, the scroll doesn´t work. If there is a button at bottom then works, but then i can't up with the scroll. Seems like i need to be a button to scroll works.

Do you understand me?

Regards

chen

What happens is that Labels does not grab focus by default, therefore
the Form does not scroll.
What you need to do is to call to Label.setFocusable(true), that will
cause your Labels to get the focus and to start scrolling the screen if
needed.

Regards,
Chen

lwuit-users@mobileandembedded.org wrote:
> In fact I think that the problem is not in the source. When I have a lot of labels (severals rows), and if there isn't a button at bottom, the scroll doesn´t work. If there is a button at bottom then works, but then i can't up with the scroll. Seems like i need to be a button to scroll works.
>
> Do you understand me?
>
> Regards
> [Message sent by forum member 'dunae' (dunae)]
>
> http://forums.java.net/jive/thread.jspa?messageID=279095
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>
>

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

dunae
Offline
Joined: 2008-06-09
Points: 0

Thank you very much. This is the solution.