Here you can find the source of updateSelectionAfterItemMoved(ListSelectionModel selectionModel, int[] previousSelection, int previousIndex, int newIndex)
public static void updateSelectionAfterItemMoved(ListSelectionModel selectionModel, int[] previousSelection, int previousIndex, int newIndex)
//package com.java2s; //License from project: Apache License import javax.swing.*; public class Main { public static void updateSelectionAfterItemMoved(ListSelectionModel selectionModel, int[] previousSelection, int previousIndex, int newIndex) { selectionModel.setValueIsAdjusting(true); selectionModel.clearSelection(); for (int index : previousSelection) { int insertion; if (index == previousIndex) { insertion = newIndex;/*from w ww. ja va 2s. c o m*/ } else { insertion = index; if (index > previousIndex) { insertion--; } if (index > newIndex) { insertion++; } } selectionModel.addSelectionInterval(insertion, insertion); } selectionModel.setValueIsAdjusting(false); } }