void (List<? extends ProjectTemplate> list, boolean preserveSelection) { list.sort((o1, o2) -> Boolean.compare(o1 instanceof ArchivedProjectTemplate, o2 instanceof ArchivedProjectTemplate)); int index = preserveSelection ? myList.getSelectedIndex() : -1; myList.setModel(new CollectionListModel<>(list)); if (myList.isEnabled()) { myList.setSelectedIndex(index == -1 ? 0 : index); } updateSelection(); }