Question

I'm developing a simple application to generated .nfo files, which are simple XML files. So I have an application which looks something like this

NFO Maker Application

As the TreeView needs a type parameter, I created a simple model for the tree. This model encapsulates the XML model, as these are only the leafs and not the nodes.

My Problem

In the picture you can see on the left the tree and on the right side the properties to be edited in the xml (tree leaf). I bind these properties (currently only the titleProperty) and everything works fine. However the TreeView is not updated when I change something in the textfield. I must double click on the TreeItem.

How can I update the TreeView to reflect changes in the editor panel?

The code is on GitHub

Was it helpful?

Solution

I think that's because the updateItem method is called only when the item of the TreeCell is replaced, not modified. What you need is a way to inform the TreeCell instance that the property of its item has changed.

For example, instead of using the method setText for modifiying the text of your treecell, try to bind the textProperty to the wanted property of your model object. Of course, you will need to update your model for using the JavaFX Property and Bindings Another solution could be to use the PropertyChangeListener, old style.

If you want example, I can try to provide one.

EDIT : a little example. I modified the text for the Episode leaf. Of course, you will need to move the episode and title properties of the EpsiodeDetails class to javafx-style properties.

@Override
protected void updateItem(ITVShowItem item, boolean empty) {
    super.updateItem(item, empty);
    if (item != null) {
        if (item instanceof Show) {
            //nothing
        } else if (item instanceof Season) {
            Season season = (Season) item;
            setText("Season " + season.getSeason());
        } else if (item instanceof Episode) {
            Episode episode = (Episode) item;
            this.textProperty().bind(Bindings.concat(episode.getDetails().episodeProperty(), " - ", episode.getDetails().titleProperty()));
            //setText(episode.getDetails().getEpisode() + " - " + episode.getDetails().getTitle());
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top