Ignore:
Timestamp:
2020-06-11T14:19:10+02:00 (4 years ago)
Author:
simon04
Message:

Add TableHelper.setSelectedIndices

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java

    r15226 r16601  
    33
    44import java.awt.Component;
     5import java.util.stream.IntStream;
    56
    67import javax.swing.JTable;
     
    147148        return rv;
    148149    }
     150
     151    /**
     152     * Selects the given indices in the selection model
     153     * @param selectionModel list selection model.
     154     * @param indices the indices to select
     155     * @see ListSelectionModel#addSelectionInterval(int, int)
     156     * @since 16601
     157     */
     158    public static void setSelectedIndices(ListSelectionModel selectionModel, IntStream indices) {
     159        selectionModel.setValueIsAdjusting(true);
     160        selectionModel.clearSelection();
     161        indices.filter(i -> i >= 0).forEach(i -> selectionModel.addSelectionInterval(i, i));
     162        selectionModel.setValueIsAdjusting(false);
     163    }
    149164}
Note: See TracChangeset for help on using the changeset viewer.