Here you can find the source of getSelectedIndecies(final ListSelectionModel lsm)
Parameter | Description |
---|---|
lsm | ListSelectionModel |
public static Collection<Integer> getSelectedIndecies(final ListSelectionModel lsm)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collection; import javax.swing.ListSelectionModel; public class Main { /**//from w ww.ja va 2 s. c o m * Returns an {@link Collection} with all indecies that are selected in the inputted * {@link ListSelectionModel}. * @param lsm ListSelectionModel * @return Collection with selected indecies */ public static Collection<Integer> getSelectedIndecies(final ListSelectionModel lsm) { Collection<Integer> selectedIndecies = new ArrayList<Integer>(); if (!lsm.isSelectionEmpty()) { // Find out which indexes are selected. int minIndex = lsm.getMinSelectionIndex(); int maxIndex = lsm.getMaxSelectionIndex(); /*System.out.println("Event for indexes " + firstIndex + " - " + lastIndex + "; selected indexes:");*/ for (int i = minIndex; i <= maxIndex; i++) { if (lsm.isSelectedIndex(i)) { selectedIndecies.add(i); } } } return selectedIndecies; } }