Reputation: 1810
I wrote a program on moving data from one list to another using JList. But when I move the selected data from one list to another, the previous enteries in the list to which I moving data gets overwritten by the new data.
How can I make program in which the previous enteries I made in a list doesn't get overwritten by the new data which I try to move?
Regards
Upvotes: 2
Views: 103
Reputation: 32391
Whenever adding an element to the list, you should add it to the list model using methods like addElement()
.
Don't add data to the JList
using setData()
or similar methods.
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
model.addElement(someElement);
Upvotes: 2
Reputation: 16234
You should use a DefaultListModel
as the JList model, and add and remove from there.
Upvotes: 2