Java ArrayLists into JList
I had trouble with toArray() and JList for my project as well. Did some research and tried a few things and found something that works. Hope it helps everyone:
ArrayList<String> i = new ArrayList<>();
String[] str = new String[i.size()];
//Assuming there is data in your list
JList<String> list = new JList<>(i.toArray(str));
JList provides a constructor JList(Object[]) which you can call after unpacking your ArrayList<String> using toArray():
list = new JList(arr.toArray())
Try this:
DefaultListModel listModel = new DefaultListModel();
for (int i = 0; i < arrayList().size(); i++)
{
listModel.addElement(arrayList().get(i));
}
jList1.setModel(listModel);