Reputation: 385
I'm new to JavaFX 8 and tried to implement a TreeTableView with some jfxtras controls in my second and third column. Therefore I set up the cell factories of those columns with custom TreeCells e.g. like this:
col3.setCellFactory(new Callback<TreeTableColumn<Object, String>, TreeTableCell<Object, String>>() {
@Override
public TreeTableCell<Object, String> call(TreeTableColumn<Object, String> param) {
TreeTableCell<Object, String> cell = new TreeTableCell<Object, String>() {
private ColorPicker colorPicker = new ColorPicker();
@Override
protected void updateItem(String t, boolean bln) {
super.updateItem(t, bln);
setGraphic(colorPicker);
}
};
return cell;
}
});
Now I can see the ColorPickers and can use them, but the column somehow does not react on expanding or collapsing the nodes of column 1 (which shows String information out of POJOs). So e.g. if I collapse the whole tree, the third column still shows all ColorPickers.
So what else is necessary to get the columns 'synced'?
Thank you!!
Upvotes: 2
Views: 1680
Reputation: 209694
When the item displayed by the cell changes, the updateItem(...)
method is invoked. If the cell is empty (e.g. because the user collapsed cells above), the second parameter will be true
; you need to check for this and unset the graphic.
So:
col3.setCellFactory(new Callback<TreeTableColumn<Object, String>, TreeTableCell<Object, String>>() {
@Override
public TreeTableCell<Object, String> call(TreeTableColumn<Object, String> param) {
TreeTableCell<Object, String> cell = new TreeTableCell<Object, String>() {
private ColorPicker colorPicker = new ColorPicker();
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
setGraphic(colorPicker);
}
}
};
return cell;
}
});
Upvotes: 1