JN_newbie
JN_newbie

Reputation: 6072

Problem in Jlist add from one list to another list

I am facing a problem in jlist in java. I have two JLists, I want to add elements from one jlist to another jlist I tried it but it add the element and remove the existing ones present in the list. Here is the code

Object[] getListItem = (Object[]) jList2.getSelectedValues();
for(int i=0;i<getListItem.length;i++){
  //jList1.setListData(jList2.getSelectedValues());
  jList1.setListData(getListItem);
}

Need Help Thanks.

Upvotes: 1

Views: 773

Answers (1)

Cameron Skinner
Cameron Skinner

Reputation: 54306

You need to add items to the ListModel, not the JList itself. The DefaultListModel class has methods for adding elements and is similar to the java.util.Vector class.

Upvotes: 3

Related Questions