Learner
Learner

Reputation: 161

JList,JScrollPane

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

Answers (2)

Msyk
Msyk

Reputation: 682

There are the following.

Rectangle rect = list.getCellBounds(list.getSelectedIndex(), list.getSelectedIndex());
list.scrollRectToVisible(rect);

Upvotes: 0

Serabe
Serabe

Reputation: 3924

list.ensureIndexIsVisible(list.getSelectedIndex()); should be enough.

Upvotes: 3

Related Questions