Java JList Select getSelectedIndecies(final ListSelectionModel lsm)

Here you can find the source of getSelectedIndecies(final ListSelectionModel lsm)

Description

Returns an Collection with all indecies that are selected in the inputted ListSelectionModel .

License

Open Source License

Parameter

Parameter Description
lsm ListSelectionModel

Return

Collection with selected indecies

Declaration

public static Collection<Integer> getSelectedIndecies(final ListSelectionModel lsm) 

Method Source Code


//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;
    }
}

Related

  1. downListSelectedIndex(JList sourceList)
  2. ensureSelectionIsVisible(final JList list)
  3. fillSelectionListFromString(JList aListComponent, String theList, boolean removeQuotes)
  4. fireSelectRow(final JList list, final Object value)
  5. fireSelectRows(final JList list, final int[] rows)
  6. getSelectedItems(DefaultListModel listModel, ListSelectionModel selectionModel)
  7. getSelectedMultipleList(JList anJList)
  8. getSelectedRows(ListSelectionModel listSelectionModel)
  9. initParamList(final JList paramList, final String[] availNames, final String[] defaultSelection)