1

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>
hermy67
  • 138
  • 2
  • 15
  • "location is required" just means the path to the FXML resource is wrong (and `getResource()` is returning `null`). The path you are giving is going to look for test.fxml in the package `scriptbuilder.controller.view`. – James_D Aug 03 '15 at 14:39
  • thank you so much! I now understood how it works and your suggestion helped. I changed my code to this. root = FXMLLoader.load(ScriptBuilder.class.getResource("view/GroupDataPrepAndMatchKey.fxml")); – hermy67 Aug 03 '15 at 15:56

0 Answers0