private void setupProfileList(final JList<MutableProfile> profileList) { selectionModel = new VetoableListSelectionModel(); profilesModel = (GenericListModel<MutableProfile>) profileList.getModel(); profilesModel.addAll(model.getProfileList()); profileList.setSelectionModel(selectionModel); selectionModel.addVetoableSelectionListener( e -> { if (!model.canSwitchProfiles()) { throw new PropertyVetoException("Cannot switch with invalid profile", e); } }); profileList.addListSelectionListener( l -> { if (!selectionModel.isSelectionEmpty()) { model.setSelectedProfile(Optional.ofNullable(profileList.getSelectedValue())); } }); }