TreeTableView doesn't refresh data - JavaFX 21

50 views Asked by At

This question was asked a few times here but none of the solutions work for me, maybe because of the latest version or other issues.

I have an object with few properties, one of which changes when a response comes back from the network. I would like to update the tree dynamically when a new value arrives (this can be cell by cell). from what I was reading you should use the StringProperty class to represent observable value.

Things I tried:

  • Registering the column using this property,

  • Adding an event listener to the property and triggering a tree update

public interface PropertyState {
    StringProperty stateProperty();

and the Tree Item (I used this from another SO answer...)

public class TableItem extends TreeItem<PropertyState> {
    public TableItem(PropertyState state) {
        super(state);
        state.stateProperty().addListener((obs, oldName, newName) -> {
           TreeModificationEvent<PropertyState> event =
               new TreeModificationEvent<>(TreeItem.valueChangedEvent(), this);
           Event.fireEvent(this, event);
        });
    }
}

Then lastly the tree view table:

TreeTableColumn<PropertyState, String> state = new TreeTableColumn<>("State");
state.setCellValueFactory(cellData -> cellData.getValue().getValue().stateProperty());

getColumns().add(state);
// more code to populate the tree with objects

So whatever I try, the cell value does not change. I can trace the network back and the StringProperty does change but the event is never triggered and the cell keeps the original value.

Seemed some wrapper or cloning was going on... Any help would be appreciated.

Made a simple code example as requested. this seemed to work fine so must have a bug in my original code.

https://github.com/gadieichhorn/78152140/tree/master

0

There are 0 answers