Arshad
Arshad

Reputation: 19

Javafx table view multiple selection sometimes skips one of the items

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?

Upvotes: 2

Views: 354

Answers (1)

Itai
Itai

Reputation: 6921

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 from table.getItems()

Upvotes: 2

Related Questions