File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Display selected item in JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Display selected item in JList" Watch "Display selected item in JList" New topic

Display selected item in JList

Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
I've got a JList that is part of JScrollPane.
I do a search in a database for a value. I then match that value with the value in the JList. I then setSelected on the item in the JList. All this is OK.
However, my JList still displays the first item in the list, not my item. I know the index of the item I want to display. This should be dead-bang easy, but for some reason, I can't think of the solution.
Thomas Suer
Ranch Hand

Joined: Sep 03, 2001
Posts: 50
What about using the JList's method
[This message has been edited by Thomas Suer (edited November 09, 2001).]
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
That was it!
Vinod Venugopal
Ranch Hand

Joined: Dec 06, 2000
Posts: 148
Hey I faced a similar problem with this setSelectedValue() method when I wanted to select multiple values in a JList automatically, it still selected only once, is there a way ?

- Vinod<br />-------<br />SCJP2
I agree. Here's the link:
subject: Display selected item in JList
jQuery in Action, 3rd edition