void () { if (!updatingListSelectionModel) { updatingListSelectionModel = true; try { // This is way expensive, ListSelectionModel needs an // enumerator for iterating. int min = listSelectionModel.getMinSelectionIndex(); int max = listSelectionModel.getMaxSelectionIndex(); clearSelection(); if (min != -1 && max != -1) { List<TreePath> selectionPaths = new ArrayList<>(); for (int counter = min; counter <= max; counter++) { if (listSelectionModel.isSelectedIndex(counter)) { TreePath selPath = myTree.getPathForRow(counter); if (selPath != null) { selectionPaths.add(selPath); } } } if (!selectionPaths.isEmpty()) { addSelectionPaths(selectionPaths.toArray(TreeUtil.EMPTY_TREE_PATH)); } } } finally { updatingListSelectionModel = false; } } }