Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.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:updatetablecell_Java_Javafx_Tableview_Javafx 8 - Fatal编程技术网

Javafx:updatetablecell

Javafx:updatetablecell,java,javafx,tableview,javafx-8,Java,Javafx,Tableview,Javafx 8,我有一个TableView和一个自定义MyTableCell扩展了CheckBoxTreeTableCell,在这个单元格中@Overrided了updateItem方法: 我有一个组合框,其中有一些项目,当我更改该组合框的值时,我希望根据所选值设置复选框的可见性。所以我有一个听众: comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {

我有一个TableView和一个自定义MyTableCell扩展了CheckBoxTreeTableCell,在这个单元格中@Overrided了updateItem方法:

我有一个组合框,其中有一些项目,当我更改该组合框的值时,我希望根据所选值设置复选框的可见性。所以我有一个听众:

comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue.equals("A") || newValue.equals("S")) {
            data.stream().filter(row -> row.getName().startsWith(newValue)).forEach(row -> row.setAvailable(false));
        }
    });
数据是一个可观察的列表 这只是我的代码的一个示例和简化版本
当我更改组合框中的值时,表格的复选框不会消失,直到我滚动或单击该单元格。存在调用table.refresh的解决方案;但是当我只想刷新一个单元格时,我不想刷新整个表。所以我尝试添加一些侦听器来触发updateItem,但每次尝试都失败了。您知道如何触发一个单元格的更新机制,而不是整个表格的更新机制吗?

绑定单元格的图形,而不仅仅是设置它:

private Binding<Node> graphicBinding ;

@Override
protected void updateItem(Boolean item, boolean empty) {
    graphicProperty().unbind();
    super.updateItem(item, empty) ;

    MyRow currentRow = getTableRow().getItem();

    if (empty) {
        graphicBinding = null ;
        setGraphic(null);
    } else {
        graphicBinding = Bindings
            .when(currentRow.availableProperty())
            .then(super.getGraphic())
            .otherwise((Node)null);
        graphicProperty.bind(graphicBinding);
    }
}

乍一看,这是一个非常好的解决方案,但我得到了RuntimeExceoption:绑定值不能设置为super.updateItem。。。在行:setGraphicnull@Sunflame有graphicProperty.unbind行吗?我不知道你怎么能在那里得到这个异常。是的,但我通过将graphicProperty.unbind与super.updateItem…交换来解决它,所以它工作得很好,非常感谢:
private Binding<Node> graphicBinding ;

@Override
protected void updateItem(Boolean item, boolean empty) {
    graphicProperty().unbind();
    super.updateItem(item, empty) ;

    MyRow currentRow = getTableRow().getItem();

    if (empty) {
        graphicBinding = null ;
        setGraphic(null);
    } else {
        graphicBinding = Bindings
            .when(currentRow.availableProperty())
            .then(super.getGraphic())
            .otherwise((Node)null);
        graphicProperty.bind(graphicBinding);
    }
}