Created
January 30, 2018 07:34
-
-
Save TheItachiUchiha/0b77f7a9c20a062bc6555828d0174a7e to your computer and use it in GitHub Desktop.
A ListCell which can be used to unselect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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