I've created a method that returns an arraylist of object now I want to display the returned arraylist in a Jlist in swing eclipse how can I do that ?
1 Answer
Create the JList with a DefaultListModel.
DefaultListModel listModel= new DefaultListModel();
for (int i = 0; i < arrayList().size(); i++)
{
listModel.addElement(arrayList().get(i));
}
JList listd = new JList(listModel);
listd.setModel(listModel);
Plese refer this answer in stackoverflow,
3 Comments
R.Rou
I'm not adding elements I'm adding an arraylist of type Object I've tried this code but it didn't work
chamzz.dot
I changed my previous answer.Please check the solution.It may be help you
R.Rou
in 3rd line listModel cannot be resolved !! I can't understand the reason