Skip to content

Instantly share code, notes, and snippets.

@TheItachiUchiha
Created January 30, 2018 07:34
Show Gist options
  • Save TheItachiUchiha/0b77f7a9c20a062bc6555828d0174a7e to your computer and use it in GitHub Desktop.
Save TheItachiUchiha/0b77f7a9c20a062bc6555828d0174a7e to your computer and use it in GitHub Desktop.
A ListCell which can be used to unselect
private class UnselectListCell<T> extends ListCell<T> {
public UnselectListCell() {
addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
if (!isEmpty()) {
MultipleSelectionModel<T> selectionModel = getListView().getSelectionModel();
int index = getIndex();
if (selectionModel.getSelectedIndices().contains(index)) {
selectionModel.clearSelection(index);
} else {
selectionModel.select(index);
}
event.consume();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment