繁体   English   中英

Javafx:更新TableCell

[英]Javafx: update TableCell

我有一个TableView和定制MyTableCell extends CheckBoxTreeTableCell<MyRow, Boolean> ,在该小区被@Overridden所述updateItem方法:

@Override
public void updateItem(Boolean item, boolean empty) {
    super.updateItem(item, empty);
    if(!empty){
        MyRow currentRow = geTableRow().getItem();
        Boolean available = currentRow.isAvailable();
        if (!available) {
            setGraphic(null);
        }else{
            setGraphic(super.getGraphic())
        }
    } else {
        setText(null);
        setGraphic(null);
    }
}

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

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));
        }
    });
  • data是一个ObservableList<MyRow>
  • 这只是一个示例,也是我代码的简化版本

当我更改comboBox中的值时,直到我滚动或单击该单元格,表格的chekbox才会消失。 有一个“解决方案”可以调用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);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM