selection in JList
Hi!
I am using JScrollbar to hold the JList and i have set the property setVisibleRowCount to 1.
List contains the values from 0..1000, if i want the default value to be displayed in the JList is 21, i have set the ensureIndexVisible property to 21, but it is showing only the first item in the list i.e 0. But item 21 is selected.
Please help me regarding this,
Thanks in advance
Raghu
hi,
first of all I'd like to say that it is not such a good idea to limit the displayed rows in a JList to one - you should use JComboBox instead. Your question concerning ensureIndexIsVisible isn't very easy to reply to, because you didn't pass your source code along. Nevertheless I suppose that the reason for this behaviour is the following: you called this function before you provided the list with the data model or before you added the list to the scroll pane, because this method is no property accessor, as you assumed, but a simple function, which advices the viewport (in the scrollpane) to scroll to a specific position. Therefore a data model must be there and, of course the viewport. So ensure that you call this method after you added a data model and after you put the list into the scrollpane.
best regards, Michael