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
?
views:
265answers:
3
+1
A:
Object[] temp = jList1.getSelectedValues();
temp[i] = the object you want.
Soldier.moth
2009-06-08 19:49:31
Are you sure that's what you want? That only works if all objects in the list are selected.
Michael Myers
2009-06-08 19:51:47
I only need to get the objects of the items that are selected, I probably forgot to say that sorry.
Soldier.moth
2009-06-08 19:56:54
+2
A:
JList dataList=(...)
for(int i = 0; i < dataList.getModel().getSize(); i++) {
System.out.println(dataList.getModel().getElementAt(i));
}
Pierre
2009-06-08 19:52:17
A:
DefaultListModel list = new DefaultListModel(); JList jl = new JList(list);
int i = 21; Object = element; String = yourElement;
element = jl.getModel().getElementAt(i); yourElement = element.toString;
Dave
2009-11-11 18:03:44