Search code examples
javalistjlistjfilechooserlistselectionlistener

(java) i want to change to "getSelectedValuesList()” from "getMinSelectionIndex();” from List in this code


Purpose

I am customizing an App for personal use. This App can make many midi files in Java.

i want to change to "getSelectedValuesList()” from "getMinSelectionIndex();” in this code

Because I want to choose and SAVE many files in one time from list. I already could select many files in one time.

(I already changed below)

public interface ListSelectionModel
{
int MULTIPLE_INTERVAL_SELECTION = 2;
}

Problems

  • I can’t save many files in one time from list.

(Error message)

getSelectedValuesList() is not defined in ListSelectionModel

My idea

I changed a chord like this. But it is error.

.getMinSelectionIndex();

=> .getSelectedValuesList();

Source cord

(Original cord)

  /**
 * To send a selected table model, that is MIDI sequence. 
 * @return => selected MIDI sequence table model. (If we don’t choose, it is null)
 */
public SequenceTrackListTableModel getSelectedSequenceModel() {
    if( sequenceListSelectionModel.isSelectionEmpty() ) return null;
    int selectedIndex = sequenceListSelectionModel.getMinSelectionIndex();
    if( selectedIndex >= sequenceList.size() ) return null;
    return sequenceList.get(selectedIndex);
}

(My Idea)

  /**
 * To send a selected table model, that is MIDI sequence. 
 * @return => selected MIDI sequence table model. (If we don’t choose, it is null)
 */
public SequenceTrackListTableModel getSelectedSequenceModel() {
    if( sequenceListSelectionModel.isSelectionEmpty() ) return null;
    int selectedIndex = sequenceListSelectionModel.getSelectedValuesList();
    if( selectedIndex >= sequenceList.size() ) return null;
    return sequenceList.get(selectedIndex);
}

Solution

  • class MyListSelectionModel extends DefaultListSelectionModel{
       public returntypeoftheExistinggetMinSelectionIndex getSelectedValuesList(){
         return getMinSelectionIndex();
       }
    }
    

    And while creating the sequenceListSelectionModel object use the new class like

    public ListSelectionModel sequenceListSelectionModel = new MyListSelectionModel ()