Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with jList and setSelectedValue

843807May 11 2010 — edited May 12 2010
Hi,

I have quite a long list of strings which I put in a jList (which I name jListRef). I want to select a specific item in this list and I want the list to scroll so that this selected item becomes visible. I tried this code :

jListRef.setSelectedIndex(c);
boolean scrollInView = true;
jListRef.setSelectedValue(jListRef.getSelectedValue(), scrollInView);

and it doesn't work. The relevant item of the list is selected, but the list does not scroll, so the selected item remains hidden, I have to scroll the list manually to make it appear.
My jList is filled with strings, so I also tried this code :

jListRef.setSelectedIndex(c);
boolean scrollInView = true;
jListRef.setSelectedValue(jListRef.getSelectedValue().*toString()*, scrollInView);

it doesn't work either (same behaviour as the upper code).

The setSelectedValue(o1,b1) method of the jList is supposed to scroll the list to the item o1 if b1 is true, so I don't get what i'm doing wrong. I just know it doesn't work.

Any help is welcome.


TIA
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2010
Added on May 11 2010
3 comments
199 views