void (ActionEvent e) { Object selected = list.getSelectedValue(); ProjectGroup group = null; if (selected instanceof ProjectGroupActionGroup) { group = ((ProjectGroupActionGroup)selected).getGroup(); } if (group != null && group.isExpanded()) { group.setExpanded(false); int index = list.getSelectedIndex(); list.setSelectedIndex(index); } }