views:

265

answers:

3

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?

+1  A: 
Object[] temp = jList1.getSelectedValues();
temp[i] = the object you want.
Soldier.moth
Are you sure that's what you want? That only works if all objects in the list are selected.
Michael Myers
I only need to get the objects of the items that are selected, I probably forgot to say that sorry.
Soldier.moth
+2  A: 
JList dataList=(...)

 for(int i = 0; i < dataList.getModel().getSize(); i++) {
     System.out.println(dataList.getModel().getElementAt(i));
 }
Pierre
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