简体   繁体   中英

Move an item from one list/arraylist to another list/arraylist

How to move an item from one list/arraylist to another list/arraylist?

Here's what I am required to do

  • Add songs from a text field to a music library ArrayList .
  • Select songs in the List Box and add them to the Playlist.
  • Select songs in the Playlist List Box and remove them from the Playlist.
  • Sort the songs in the Playlist.

I finally figured out how to add items to an arraylist and display them in a listbox. Now I need to know how to select them and move them to another list/array using a button.

Any ideas?

It will be easier for you to use ListModel as suggested by MadProgrammer

You can try like this

model = new DefaultListModel<String>();
    for(String str : playlist){
         model.addElement(str);
    }    
    listPlaylist.setModel(model);     
    listPlaylist.setSelectedIndex(0);

You can create two models for library and playlist and perform operations

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM