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

后端 未结 4 525
感动是毒
感动是毒 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:35

    as you don't show any code, all I can say is this:

    assuming you are using, for example, an arrayList of custom objects as a source of data for each list, you could have a button that when pressed, gets the selected item index, grabs that object and then you add it to the other list.

    method for the pressed button event (){
        arrayList2.add(arrayList1.get(jList1.getSelectedIndex());
    }
    

    after this you can just reload the model on jlist2 so it shows the new data.

    hope it helps

提交回复
热议问题