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

270 views Asked by At

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);
}
3

There are 3 answers

0
robin On BEST ANSWER
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 () 
1
Dan On

hummm... I tried to write like this. I think your explain means like this. Now there is no error message, but i could't save files at the same time.

Im wondering about Type of "returnTypeOfTheExisting" and "getSelectedValuesList()". Because these contains MIDI sequence file. these are not "Int".... I expect I need to change it.

package javax.swing;

import javax.swing.*;
import java.awt.*;

public class MyListSelectionModel extends DefaultListSelectionModel {
        public int returnTypeOfTheExisting = getMinSelectionIndex();

    int getSelectedValuesList() {
         return getMinSelectionIndex();
       };
    }

--

public ListSelectionModel sequenceListSelectionModel = new MyListSelectionModel();
1
Dan On

I need to use ArrayList?

public class MyListSelectionModel extends DefaultListSelectionModel {
public ArrayList<String> returnTypeOfTheExisting = getSelectedValuesList();

ArrayList<String> getSelectedValuesList() {
    ArrayList<String> testSelect = new ArrayList<String>();
    ListModel<String> starsCohort = null;
    JList<String> starsList = new JList<String>(starsCohort);
    testSelect.addAll(starsList.getSelectedValuesList());
    return (testSelect);
};

}

I am so sorry. maybe i don't good knowledge about java.