I have created a table view in javafx for my custom object. I have enabled multiple selection in the code by doing:
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Randomly I observe that when I select all the items by pressing Ctrl+A, one of the items is returned as null among all the selected items. Not sure why this happens. I use below line to fetch all items:
ObservableList<MyObj> selectedItems = table.getSelectionModel().getSelectedItems();
Any suggestions?
Apparently it's a bug, already fixed for version 9 (and also 8u112, if I understand correctly): https://bugs.openjdk.java.net/browse/JDK-8144501
A workaround for now is to use
getSelectedIndices()
, then get the items corresponding to these instances fromtable.getItems()