Adding string to a JList?

I'm trying to figure out how to add a new list to a JList control.  I know
how to add it w/ JList() constructor, but how about after the list is
already created and later depending o a condition you need to add another
string into it?  Cant seem to find a addItem method like in 1.1?

1.  Listbox is already created and some data is inserted. Then later I need
to add another string.  What would I need to dol


Who is Participating?
heyhey_Connect With a Mentor Commented:
you have to use ListModel directly

DefaultListModel model = new DefaultListModel();
JList list = new JList(model);

// now use
model.addElement("new element");
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.
Thank you,
Moderator @ Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.