I am trying to call an fxml (test.fxml) into another fxml (main.fxml) in center of body pane. I am actually doing this in the controller class of main.fxml. No matter how many different ways I try, I am just not able to set the center element at all.
Requirement is, I need to display different fxml files on right click of tree structure in main fxml file.
but when I call this method, I get the exception 'location is required'. Is there something I need to do? Please help.
main.fxml
@FXML
TreeView<String> mainTree;
@FXML
BorderPane rootLayout;
@FXML
AnchorPane dynamicContent;
ContextMenu cntxtMenu;
//Method where i am trying to set main.fxml center body
public void showAttributeScreen(){
FXMLLoader loader = new FXMLLoader(scriptbuilder.controller.TestController.class.getResource("view/test.fxml"));
AnchorPane pane = new AnchorPane();
try{
pane = (AnchorPane) loader.load();
rootLayout.setCenter(pane);
}
catch(Exception e){
}
}
test.fxml
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" fx:controller="scriptbuilder.controller.TestController">
<Label alignment="BASELINE_CENTER" text="Hi" />
</AnchorPane>