Find out if JList has an item currently selected
I have a JList which is populated after importing a file. Is it possible to have the first item/element of the JList highlighted/selected. I have browsed many places hoping to find a line along the lines of
list.setFocus(0);
//or
listSelectionEvent.setSelection(0);
//0 referring to index point of the list
开发者_JAVA技巧
Maybe this isn't even possible... ?
Use:
list.setSelectedIndex(0);
精彩评论