从 JavaFX 2.0 中的 TableView 读取多项选择
我试图从 JavaFX 2.0 中的 TableView 中获取选择。我在 TableView 中存储了 5 个人(5 行)。获取选择模型的代码是:
TableView<Person> tableView =
myStage.getTableView();
ObservableList<Person> selection =
tableView.getSelectionModel().getSelectedItems();
System.out.println(selection.size());
现在,当我选择多行,然后执行包含上述代码的方法时,以下内容会打印选择 * 2,有时会打印选择 * 3。例如:我选择所有 5 行,它会打印尺寸为 10,有时为 15!
我在这里做错了什么?
I am trying to get the selection from a TableView in JavaFX 2.0. I have stored 5 Persons (5 rows) in the TableView. The code to get the selection model is:
TableView<Person> tableView =
myStage.getTableView();
ObservableList<Person> selection =
tableView.getSelectionModel().getSelectedItems();
System.out.println(selection.size());
Now when I select multiple rows and then execute the method including the above code, the following prints the selection * 2 and sometimes the selection * 3. For example: I select all 5 rows and it prints out a size of 10 and sometimes 15!
What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TableView 存在一个错误,它会返回重复的项目以供通过 Shift 键单击进行选择。
作为修复之前的解决方法,您可以尝试通过以下方式过滤重复的项目:
There is a bug with TableView returning duplicated items for selection made by shift-click.
As a workaround until fix you can try filter duplicated items by: