Krishna
Krishna

Reputation: 780

How to add tags to an fxml file through controller in javafx?

 <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;}"/>

In the above fxml code I want to add one more <TreeView> but through the controller. How can I do this?

Upvotes: 0

Views: 149

Answers (1)

Nikos Paraskevopoulos
Nikos Paraskevopoulos

Reputation: 40318

You will have to:

  1. Give a fx:id to the AnchorPane:

    <AnchorPane fx:id="theAnchorPane">
    
  2. Add the corresponding field in the controller:

    @FXML private AnchorPane theAnchorPane;
    

From the code that performs the addition you have to:

  1. Create the new TreeView however you like:

    TreeView newTreeView = ...;
    
  2. Add it to the childen of the AnchorPane, possibly with some constraints:

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

Upvotes: 1

Related Questions