如何通过javafx中的控制器向fxml文件添加标记?

如何通过javafx中的控制器向fxml文件添加标记?,javafx,fxml,Javafx,Fxml,在上面的fxml代码中,我想通过控制器再添加一个。我该怎么做 您必须: 将fx:id交给AnchorPane: <AnchorPane> <TreeView fx:id="locationTreeView" focusTraversable="true" prefHeight="449.0" prefWidth="725.0" style="#tree&#10;{&#10;-fx-border-style:solid;&#10;-fx-bo

在上面的fxml代码中,我想通过控制器再添加一个
。我该怎么做

您必须:

  • fx:id
    交给
    AnchorPane

     <AnchorPane>
    <TreeView fx:id="locationTreeView"  focusTraversable="true" prefHeight="449.0"      prefWidth="725.0" style="#tree&#10;{&#10;-fx-border-style:solid;&#10;-fx-border-width:1px;&#10;-fx-border-color:#ffffff;&#10;}"/>
    
  • 从执行添加的代码中,您必须:

  • 创建新的
    TreeView
    ,您可以选择:

    @FXML private AnchorPane theAnchorPane;
    
  • 将其添加到
    AnchorPane
    的子对象,可能有一些限制:

    TreeView newTreeView = ...;
    
  • TreeView newTreeView = ...;
    
    theAnchorPane.getChildren().add(newTreeView);
    AnchorPane.setTopAnchor(newTreeView, ...); // etc