Reputation: 161
My JList has >100 values. when the screen is loaded the i have set the selected index of the list to 50 and added the JList to a JScrollPane. the value is getting selected but the JScrollPane is not getting adjusted to display that value. can anyone pleases tel me how to do that.
Upvotes: 1
Views: 1207
Reputation: 682
There are the following.
Rectangle rect = list.getCellBounds(list.getSelectedIndex(), list.getSelectedIndex());
list.scrollRectToVisible(rect);
Upvotes: 0
Reputation: 3924
list.ensureIndexIsVisible(list.getSelectedIndex());
should be enough.
Upvotes: 3