Javafx table view multiple selection sometimes ski

2019-02-19 18:30发布

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?

1条回答
爷、活的狠高调
2楼-- · 2019-02-19 18:50

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

查看更多
登录 后发表回答