File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JavaFX and the fly likes FXML Tree event handling example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "FXML Tree event handling example" Watch "FXML Tree event handling example" New topic

FXML Tree event handling example

Sourin K. Sen
Ranch Hand

Joined: May 02, 2006
Posts: 86

I couldn't find an example of a tree created in FXML using scene builder with proper event handling.
Here's what I am trying to do:
I have created a TreeView using SceneBuilder and want the Tree to display the FileSystem.
I have a controller for this FXML where in the initialize method I am initializing the tree (systemTree) via the following code :

Obviously, I have a custom TreeItem class :

Now here's the problem I am facing:
The tree displays the FileSystem root as a treenode but it does not calls the event handler for the node.
There seems to be some link missing between the FilePathTreeItem and the Tree Node because of which it does not calls the handler method of FilePathTreeItem.
I just can't figure out how to link a mouse click/dblclick event on a tree node via the TreeView to the handler of that FilePathTreeItem.

Can someone please just post a simple Tree example with node event handlers via FXML?

Thanks & Regards,
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1101

Hi Sourin,
For, all your nodes, you create an instance of your custom class FilePathTreeItem (which is where the event handlers are added), but, for your rootNode, you are only creating an instance of CheckBoxTreeItem. I don't see the event handlers for the root node added anywhere.

I agree. Here's the link:
subject: FXML Tree event handling example
It's not a secret anymore!