Javafx table view multiple selection sometimes skips one of the items
Asked Answered
C

1

2

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?

Complect answered 1/4, 2016 at 10:7 Comment(3)
Can you provide a minimal, complete, verifiable example exhibiting this behavior?Illlooking
maybe the index -1 ?Hypsography
i see the same issue, the index returned for the null object is -1 . #36894479. Were you able to fix this ?Agnosia
I
2

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()

Illlooking answered 5/7, 2016 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.