I'm new in Java and I need a help. I want to add event to specific TreeItem in my TreeView. I have some code and it doesn't work. What am I doing wrong?
Here's my code:
TreeItem<String> item = new TreeItem<>(s);
item.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>(){
public void handle(MouseEvent e) {
System.out.println("Hello World");
}
});
this.item.getChildren().add(item);
It creates a TreeView, but the event doesn't work.
Thanks for your help.