Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the text from a component in a JList?

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?

like image 268
Bobby Avatar asked Dec 10 '22 20:12

Bobby


2 Answers

JList dataList=(...)

 for(int i = 0; i < dataList.getModel().getSize(); i++) {
     System.out.println(dataList.getModel().getElementAt(i));
 }
like image 139
Pierre Avatar answered Dec 23 '22 06:12

Pierre


Object[] temp = jList1.getSelectedValues();
temp[i] = the object you want.
like image 22
Bobby Avatar answered Dec 23 '22 06:12

Bobby