Jcfg.J Jcfg.J - 2 months ago 7
Java Question

MouseEvent Listeners/EventTypes for TreeItems

Basically, I have a TreeView

TreeView<String> treeView = new TreeView<String>();


The root

TreeItem<String> root = new TreeItem<String>();
treeView.setRoot(root);


And lastly an item inside the root

TreeItem<String> item1 = new TreeItem<String>();
root.getChildren().add(item1);


(With or without more siblings or adding more children to
item1
)
And what I want to do is add a listener or EventHandler specifically for
item1
(and any siblings) so when a user double clicks on it or changes its value, something happens. I also want to know if there are any of these that show the oldValue and newValue of the TreeItem when it is edited.

The only leads I really have are that it probably has to do with using:

root.getChildren().addListeners()...
treeView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener...


or

item1.addEventHandler(...


Any help is very appreciated!

Answer

I also want to know if there are any of these that show the oldValue and newValue of the TreeItem when it is edited.

Are you just looking for

item1.valueProperty().addListener((obs, oldValue, newValue) -> {
    // do whatever you need with oldValue and newValue
});

?

Comments