Swing equivalent of the .NET ListBox

.net, java, jlist, listbox, swing

Solution

JList inside of a JScrollPane.

To add and remove items dynamically, you will want to make use of a DefaultListModel as follows:

DefaultListModel<String> listModel = new DefaultListModel<String>();
JList<String> list = new JList<String>(listModel);
JScrollPane scroll = new JScrollPane(list);
someComponent.add(scroll);

listModel.addElement("new");
listModel.remove(0);

Problem

What is the Swing equivalent of the .NET ListBox that has the ability to add new items?

Original source