如何在选择JList中的多个数据时获取所选索引号

时间:2012-07-14 07:20:09

标签: java swing return jlist

    try{
    f = new ProjectFile();

    numProject = f.getOutput();

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

//从另一个文件中检索数据并将标题存储到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){
}

1 个答案:

答案 0 :(得分:3)

使用getSelectedIndices()方法

public int[] getSelectedIndices()

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