--- old/src/java.desktop/share/classes/javax/swing/DefaultListSelectionModel.java 2017-10-20 16:03:56.217712999 +0530 +++ new/src/java.desktop/share/classes/javax/swing/DefaultListSelectionModel.java 2017-10-20 16:03:56.049796999 +0530 @@ -95,6 +95,7 @@ * @throws IllegalArgumentException {@inheritDoc} */ public void setSelectionMode(int selectionMode) { + int oldMode = this.selectionMode; switch (selectionMode) { case SINGLE_SELECTION: case SINGLE_INTERVAL_SELECTION: @@ -104,6 +105,23 @@ default: throw new IllegalArgumentException("invalid selectionMode"); } + + /* + This code will only be executed when selection needs to be updated on changing selection mode. + It will happen only if selection mode is changed from MULTIPLE_INTERVAL to SINGLE_INTERVAL or SINGLE + or from SINGLE_INTERVAL to SINGLE + */ + if (oldMode > this.selectionMode) { + if (this.selectionMode == SINGLE_SELECTION) { + setSelectionInterval(minIndex, minIndex); + } else if (this.selectionMode == SINGLE_INTERVAL_SELECTION) { + int selectionEndindex = minIndex; + while (value.get(selectionEndindex+1)) { + selectionEndindex++; + } + setSelectionInterval(minIndex, selectionEndindex); + } + } } /** {@inheritDoc} */