How to Transfer selected objects from one JList to another JList in swing?

后端 未结 4 519
感动是毒
感动是毒 2021-01-28 03:50

I want to transfer the selected objects from one JList to another JList, say List1 and List2.

4条回答
  •  隐瞒了意图╮
    2021-01-28 04:32

    try something like this. it will work fine

    DefaultListModel dlm = new DefaultListModel();   
    jButtonActionPerformed {
        jList2.setModel(dlm);
        jList1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        for (Iterator it = jList1.getSelectedValuesList().iterator(); it.hasNext();) {
            String sel = (String) it.next();
            if (dlm.contains(sel)) {
            } else {
                dlm.addElement(sel);
    
            }
        }
    }
    

提交回复
热议问题