我有一个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中更改值时,该表的车颊框在滚动或单击该单元格之前不会消失。有一个“解决方案”来调用table.refresh();,但是当我只想刷新一个单元格时,我不想刷新整个表。因此,我试图添加一些侦听器来触发updateItem,但每次尝试都失败了。您知道如何才能触发一个单元而不是整个表的更新机制吗?
发布于 2017-06-22 11:19:57
绑定单元格的图形,而不是仅仅设置它:
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);
}
}https://stackoverflow.com/questions/44695888
复制相似问题