Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Set focus on selected item in scrollable JList  RSS feed

 
Robin Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Robin Sharma
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JList.ensureIndexIsVisible(int index) to the rescue
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!