void () { int selected = myPatternList.getSelectedIndex(); String selection = selected >= 0 ? myModel.get(selected) : null; fillList(Collections.list(myModel.elements())); if (selection != null) { int toSelect = myModel.indexOf(selection); if (toSelect >= 0) { myPatternList.setSelectedIndex(toSelect); myPatternList.ensureIndexIsVisible(toSelect); } } }