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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.