-1

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 1

0

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,

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not adding elements I'm adding an arraylist of type Object I've tried this code but it didn't work
I changed my previous answer.Please check the solution.It may be help you
in 3rd line listModel cannot be resolved !! I can't understand the reason

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.