[英]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.