Skip to main content

List item selection problem

7 replies [Last post]
jede
Offline
Joined: 2007-08-02

Hi,

is there a way to ensure that the selected list item is visible in the current list view?
When I call List.setSelectedIndex() then the list does not scroll to the specified item when it's not visible. Isn't this the standard behaviour? In Swing it is.
I know, there's the scrollRectToVisible() method, but it's very complicated to calculate the rectangle of the selected item, e.g. it's not possible to get the item height easily.

Is this a bug or just not possible yet?

Keep up the great work, LWUIT is wonderfull,
Stefan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cinsulan
Offline
Joined: 2008-04-19

And if my first solution doesn't work wouldn't something like this work:

Component renderer = myList.getRenderer();
int height = renderer.getHeight() + c.getStyle().getMargin( Component.BOTTOM );
int y = height * myList.getSelectedIndex();
myList.scrollRectToVisible( new Rectangle( c.getX(), y, c.getWidth(), c.getHeight() ) );

You might have to adjust for the TOP margin or maybe some padding in the list, but I think it might actually do it.

Claes

cinsulan
Offline
Joined: 2008-04-19

In the mean time, you can try something like this:

Component c = (Component)myList.getRenderer();
myList.scrollRectToVisible( new Rectangle( c.getX(), c.getY(), c.getWidth(), c.getHeight() ) );

Claes Insulander

Shai Almog

Hi Claes,
This won't work as expected since the position of the renderer would
be incorrect.

Thanks,
Shai.

> In the mean time, you can try something like this:
>
> Component c = (Component)myList.getRenderer();
> myList.scrollRectToVisible( new Rectangle( c.getX(), c.getY(),
> c.getWidth(), c.getHeight() ) );
>
> Claes Insulander
> [Message sent by forum member 'cinsulan' (cinsulan)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284970
>
> ---------------------------------------------------------------------
> 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

cinsulan
Offline
Joined: 2008-04-19

Well,

It doesn't work like one would like it to work, but it does the job for me. I have a list in the CENTER of a BorderLayout and another (hidden) pane with details in the SOUTH position. When the user selects an item in the list, the pane in the SOUTH is displayed. This reduces the size of the list to the amount of the height of the now visible SOUTH pane.

If the user selects an item in the bottom part of the list, it will not be visible when the SOUTH component becomes visible. By using the renderer code above, the selected item is indeed shown because the list scrolls down to the selected item.

I didn't play around enough with this to figure out why this works, and I cannot remember why I came up with it, but it works well enough for now.

Naturally, I don't know if what I did can be applied to the above described situation, but it might be worth trying. You can see a rather dysmal demo at: http://www.zitadell.net/sites/default/files/listscroller.swf

Shai Almog

> If the user selects an item in the bottom part of the list, it will
> not be visible when the SOUTH component becomes visible. By using
> the renderer code above, the selected item is indeed shown because
> the list scrolls down to the selected item.

This works for you because the code occurs after rendering the list
not before rendering it. We always render the selected element last
so this is really an implementation details ;-)
The next version will have this support by default.

> I didn't play around enough with this to figure out why this works,
> and I cannot remember why I came up with it, but it works well
> enough for now.
>
> Naturally, I don't know if what I did can be applied to the above
> described situation, but it might be worth trying. You can see a
> rather dysmal demo at: http://www.zitadell.net/sites/default/files/
> listscroller.swf

I think thats a rather nice demo ;-)

BTW for this particular use case maybe you can try setting the list
to FIXED_CENTER so that the selection is always at the center of the
screen....
Have you looked at our renderer demo in LWUIT demo and the fisheye
renderer?

Why not try a similar fisheye UI where the full contact details are
shown in the selection itself?

Thanks,
Shai.

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

cinsulan
Offline
Joined: 2008-04-19

Thanks Shai,

I'm planning to brush up the look and feel later on and study your source carefully for refactoring ideas. Need to complete the app first.

Shai Almog

Hi Stefan,
you are correct that functionality should be there by default. I will
try to add it for the next drop.

Thanks,
Shai.

> Hi,
>
> is there a way to ensure that the selected list item is visible in
> the current list view?
> When I call List.setSelectedIndex() then the list does not scroll
> to the specified item when it's not visible. Isn't this the
> standard behaviour? In Swing it is.
> I know, there's the scrollRectToVisible() method, but it's very
> complicated to calculate the rectangle of the selected item, e.g.
> it's not possible to get the item height easily.
>
> Is this a bug or just not possible yet?
>
> Keep up the great work, LWUIT is wonderfull,
> Stefan
> [Message sent by forum member 'jede' (jede)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284258
>
> ---------------------------------------------------------------------
> 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