Java Utililty Methods JList Select

List of utility methods to do JList Select

Description

The list of methods to do JList Select are organized into topic(s).

Method

voidsetSelectedValue(JList list, Object value)
set Selected Value
list.setSelectedValue(value, true);
voidsetSelectedValues(JList jList, Object[] values)
set Selected Values
int[] indices = new int[values.length];
for (int i = 0; i < values.length; i++)
    indices[i] = indexOf(jList, values[i]);
jList.setSelectedIndices(indices);
voidsetSelection(JList list, Object element)
set Selection
for (int i = 0; i < list.getModel().getSize(); i++) {
    Object value = (Object) list.getModel().getElementAt(i);
    if (value == element) {
        list.setSelectedIndex(i);
        list.scrollRectToVisible(list.getCellBounds(i, i));
        return;
voidupdateSelectionAfterItemMoved(ListSelectionModel selectionModel, int[] previousSelection, int previousIndex, int newIndex)
update Selection After Item Moved
selectionModel.setValueIsAdjusting(true);
selectionModel.clearSelection();
for (int index : previousSelection) {
    int insertion;
    if (index == previousIndex) {
        insertion = newIndex;
    } else {
        insertion = index;
...