| Author |
Set focus on selected item in scrollable JList
|
Robin Sharma
Ranch Hand
Joined: Aug 24, 2005
Posts: 76
|
|
Howdy! I am using a Jlist to display a list of users. The structure is as below: DefaultListModel(containing the list of users (Strings))->JList -> JScrollPane -> JPanel -> JDialog. Now i want that when the focus is on the list and the user presses a key (alphabet like 'a' or 'B') the list should auto-scroll to the first name that starts with that alphabet. I am able to set the selected index in the list (using a key listener attached the list) but somehow if the name is not visible in the list at that moment, the list doesn't scroll to that name . Do i need to add some listener to the scroll pane also? Thanks.
|
DW
There is always a bug :-)
|
 |
Robin Sharma
Ranch Hand
Joined: Aug 24, 2005
Posts: 76
|
|
JList.ensureIndexIsVisible(int index) to the rescue
|
 |
 |
|
|
subject: Set focus on selected item in scrollable JList
|
|
|