Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaFX网格中插入行时如何更正显示问题?_Java_Javafx 8 - Fatal编程技术网

在JavaFX网格中插入行时如何更正显示问题?

在JavaFX网格中插入行时如何更正显示问题?,java,javafx-8,Java,Javafx 8,我想使用“插入”按钮在网格中插入一个新的JavaFXbean。除了显示问题外,一切正常。插入后,“重影选择”将显示在网格的下方,如此屏幕截图所示。在本例中,根据请求添加并选择了第四节bean。但是在最后一个真实bean的下面10行出现了一个假选择,其中没有为这一行设置bean 有没有人经历过这种行为?有什么线索可以帮你摆脱这个鬼选择吗?以下是“插入”按钮的代码: @FXML private Button insert; ... insert.setOnAction(event ->

我想使用“插入”按钮在网格中插入一个新的JavaFXbean。除了显示问题外,一切正常。插入后,“重影选择”将显示在网格的下方,如此屏幕截图所示。在本例中,根据请求添加并选择了第四节bean。但是在最后一个真实bean的下面10行出现了一个假选择,其中没有为这一行设置bean

有没有人经历过这种行为?有什么线索可以帮你摆脱这个鬼选择吗?以下是“插入”按钮的代码:

@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);
  };
根据,
SelectionModel.java
不公开任何
focus()
方法<代码>FocusModel.java则相反。因此,JVM将无法编译呈现的代码

以下是一个可能的解决方案:

insert.setOnAction(event -> {
    JfxBean newBean = createBean();
    tableView.getItems().add(newBean);
    int index = tableView.getItems().indexOf(newBean);
    tableView.getSelectionModel().clearSelection();
    tableView.requestFocus();
    tableView.scrollTo(index);
    // below line is the amendment
    tableView.getFocusModel().focus(index);
    tableView.getSelectionModel().select(index);
};

最后,添加
tableView.refresh()
纠正了这种奇怪的行为。没有更多的幽灵选择。

谢谢您的回复。然而,这个修正案并没有改变行为,但我会保留它。从我到目前为止所做的测试来看,这个奇怪的行为与所选模型有关。我已经能够通过只选择网格中的一个单元格来生成重影选择。此问题与插入无关。似乎添加
tableView.refresh()
紧跟在
tableView.getSelectionModel()之后。选择(索引)更正了该问题。我会做更多的测试来验证这一点。