How to Update a TreeView in JavaFX with data from users

半世苍凉 提交于 2019-11-29 18:04:24
@FXML
public void newProjectClicked(ActionEvent event){
    try{
        flag = true;
        FXMLLoader fxml = new FXMLLoader(getClass().getResource("newProjectWindow.fxml"));
        Parent root = (Parent) fxml.load();         
        Stage newWindow = new Stage();
        newWindow.setTitle("New Project");
        newWindow.initModality(Modality.APPLICATION_MODAL);
        newWindow.setScene(new Scene(root));

        // showAndWait blocks execution until the window closes:
        newWindow.showAndWait();

        NewProjectWindowController controller = fxml.getController();
        String input = controller.getInput();
        if (input != null) {
            TreeItem<String> currentItem = treeView.getSelectionModel().getSelectedItem();
            if (currentItem == null) currentItem = treeView.getRoot();
            currentItem.getChildren().add(new TreeItem<>(input));
        }

    } catch (Exception e) {
        System.out.println("caiu na exceção");
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!