Reputation: 18315
I have a JList
and I am wanting to get the text of an entry of that list at a specific index. Could someone inform me how to do this or should I restructure my code to getValues
instead of getIndices
?
Upvotes: 3
Views: 12534
Reputation: 6554
String nick = jListNicknames.getModel().getElementAt(index).toString();
System.out.println(nick);
Upvotes: 0
Reputation: 11
DefaultListModel list = new DefaultListModel();
JList jl = new JList(list);
int i = 21;
Object = element;
String = yourElement;
element = jl.getModel().getElementAt(i);
yourElement = element.toString;
Upvotes: 1
Reputation: 35306
JList dataList=(...)
for(int i = 0; i < dataList.getModel().getSize(); i++) {
System.out.println(dataList.getModel().getElementAt(i));
}
Upvotes: 8
Reputation: 18315
Object[] temp = jList1.getSelectedValues();
temp[i] = the object you want.
Upvotes: 2