如何在JavaFX中的TreeView中动态设置新的TreeItems

时间:2017-02-23 16:41:20

标签: javafx

我的代码在treeView中覆盖了我的treeItems。见图。

点击文件>>新项目是新窗口打开的时间。

Here you can see that there is a treeItem with a leaf in the left of the window. When I am just to add a new item and click in Enter my first treeItem is replaced by the last one.

我的方法出了什么问题?

public void doTree(String projectName){     
        TreeItem<String> root = new TreeItem<>(projectName);

        //the next 2 lines is just to verify eventual leafs
        TreeItem<String> leaf = new TreeItem<>(projectName + " leaf");
        root.getChildren().addAll(leaf);        

        root.setExpanded(true);
        treeView.setRoot(root); 

    }

0 个答案:

没有答案