Javafx表视图多个选择有时会跳过其中一个项目 [英] Javafx table view multiple selection sometimes skips one of the items
问题描述
我在javafx中为自定义对象创建了一个表视图。我在代码中启用了多个选择:
table.getSelectionModel()。setSelectionMode(SelectionMode.MULTIPLE);
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);
我随机观察到当我按 Ctrl + A 选择所有项目时,其中一个项目返回为 null 在所有选定的项目中。不知道为什么会这样。
我使用下面的行来获取所有项目:
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();
有什么建议吗?
推荐答案
显然这是一个错误,已经针对版本9修复了(如果我理解的话,也是8u112): https://bugs.openjdk.java.net/browse/JDK-8144501
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
目前的解决方法是使用 getSelectedIndices()
,然后从 table.getItems()
A workaround for now is to use getSelectedIndices()
, then get the items corresponding to these instances from table.getItems()
这篇关于Javafx表视图多个选择有时会跳过其中一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!