[英]Javafx: update TableCell
I have a TableView
and a custom MyTableCell extends CheckBoxTreeTableCell<MyRow, Boolean>
, In this cell is @Overridden
the updateItem
method: 我有一个
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);
}
}
I have a ComboBox<String>
where I have some items, and when I change the value of that combobox I want to set the visibility of the checkboxes depending on selected value. 我有一个
ComboBox<String>
,其中有一些项目,当我更改该组合框的值时,我想根据所选值设置复选框的可见性。 So I have a listener: 所以我有一个听众:
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
is an ObservableList<MyRow>
data
是一个ObservableList<MyRow>
When I change the value in comboBox the table's the chekboxes don't disappear until I scroll or click on that cell. 当我更改comboBox中的值时,直到我滚动或单击该单元格,表格的chekbox才会消失。 There is a "sollution" to call
table.refresh();
有一个“解决方案”可以调用
table.refresh();
but I don't want to refresh the whole table, when I want to refresh just one cell. 但是当我只想刷新一个单元格时,我不想刷新整个表。 So I tried to adding some listeners to trigger the updateItem, but I failed at every attempt.
因此,我尝试添加一些侦听器来触发updateItem,但每次尝试均失败。 Do you have any idea how can I trigger the update mechanism for one cell, not for the whole table?
您是否知道如何触发一个单元格而不是整个表的更新机制?
Bind the cell's graphic, instead of just setting it: 绑定单元格的图形,而不仅仅是设置它:
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.