简体   繁体   中英

How to get the selected index number when multiple data in JList is selected

    try{
    f = new ProjectFile();

    numProject = f.getOutput();

    String[] projectData = new String[numProject.length];

//retrieving data from another file and store the title to projectData

        for (int i = 0; i < projectData.length; i++) {
            projectData[i] = numProject[i].getProjectTitle();
        }

        listProject.setListData(projectData);
        System.out.println(listProject.getSelectedIndex());
}catch(Exception e){
}

use getSelectedIndices() method

public int[] getSelectedIndices()

Returns an array of all of the selected indices, in increasing order. 

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