java - How to correct a display problem when inserting a row in a JavaFX grid?
问题描述
I want to insert a new JavaFX bean in a grid using an "insert" button. Everything is fine, except for a display problem. After insertion, a "ghost selection" is displayed lower in the grid, as shown in this screenshot. In this example, a fourth section bean was added and selected as requested. But a fake selection appears 10 lines under the last real bean, where no bean is set for this row.
Has anyone experienced this kind of behavior? Any clue how get rid of this ghost selection? Here is what the code for the insert button looks like:
@FXML
private Button insert;
...
insert.setOnAction(event -> {
JfxBean newBean = createBean();
tableView.getItems().add(newBean);
int index = tableView.getItems().indexOf(newBean);
tableView.getSelectionModel().clearSelection();
tableView.requestFocus();
tableView.scrollTo(index);
tableView.getSelectionModel().focus(index);
tableView.getSelectionModel().select(index);
};
解决方案
最后,添加tableView.refresh()
纠正了这种奇怪的行为。没有更多的幽灵选择。
推荐阅读
- python - pyhamcrest - 比较两个列表
- graphql - 如何在其他文件中使用graphql类型进行关系而不重复
- qt - QML:原始模型中的动态视图重新排序
- android - Xamarin UITest ScrollDownTo for Android 真的很慢
- javascript - 如何在 CSS 规则中选择具有 Windows 格式路径的属性?
- node.js - 如何使用 Node.js 和 Axios 将文件上传到 AWS 中的预签名 URL?
- mysql - 如何在 Mariadb 的 regexp_replace 中使用正则表达式标志?
- javascript - 如何从firestore数据库返回值?
- c++ - 静态成员声明为 const 但初始化为 constexpr
- arrays - 带有姓名、姓氏等的 Java 数组