Creating a JavaFX TreeView using Scene Builder


I'm starting working with JavaFX and wish to use the new tree view (as you can use multiple icons to represent your data - which is what I wish to take advantage of).

I have created a basic form/scene that has a tree view and one button on it. When this button is pressed I wish to populate the treeview.

Now, all the examples ive looked at are where the form/scene is generated in code and the treeview is bound to that do I have a pre designed form with Scene builder and populate it from external code?

6/27/2016 9:46:43 AM

You could use the following code in a controller class. Inside the FXML file you will need to set the FXID to selectionTreeView. Tested in JDK 8u5 and it worked.

TreeView selectionTreeView;
private void handleButtonAction(ActionEvent event) {

public void createTree(String... rootItems) {
    //create root
    TreeItem<String> root = new TreeItem<>("Root");
    //create child
    TreeItem<String> itemChild = new TreeItem<>("Child");
    //root is the parent of itemChild
4/21/2014 8:58:14 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow