title: JavaFX 8 loading multiple fxml files into borderpane
body: <p>Given the following code:</p>
  
  <p>public class Main extends Application {</p>
  
  <pre><code>private BorderPane rootLayout;
  private VBox toolbarLayout;
  
  private URL path;
  
  public static void main(String[] args) {
      launch(args);
  }
  
  @Override
  public void start(Stage stage) {                            
  
      FXMLLoader loader = new FXMLLoader();                
  
      // Root View
  
      path = getClass().getResource("mainLayout.fxml");
      try {
          loader.setLocation(path);            
          rootLayout = (BorderPane) loader.load();
      } catch (IOException e){
          System.out.println("Not found: " + path);
          e.printStackTrace();
      }        
  
      // Toolbar View
      path = getClass().getResource("toolbar/toolbarView.fxml");  
      try {                        
          toolbarLayout = (VBox) loader.load();
      } catch (IOException e){
          System.out.println("Not found: " + path);
          e.printStackTrace();
      }
  
      rootLayout.getChildren().add(toolbarLayout);
  
      Scene scene = new Scene(rootLayout);        
      stage.setScene(scene);
      stage.show();
  }
  </code></pre>
  
  <p>If I comment out the second fxml 'try' the rootLayout loads fine. If I comment out the borderpane and set the toolbarView as the main view it works fine too.
  BUT if I try to load the toolbarView into the rootLayout, the rootLayout loads fine, but the toolbarView throws an exception:</p>
  
  <pre><code>javafx.fxml.LoadException: Root value already specified.
  </code></pre>
  
  <p>Obviously I don't understand the fxml load process well enough, so can someone please throw some light on this? Why does it think I am trying to set the root again?</p>
  
  <p>For completeness, here is the toolbarView.fxml:</p>
  
  <pre><code>&lt;VBox fx:id="idToolbar" alignment="TOP_CENTER" maxHeight="-Infinity"
   maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
    prefHeight="400.0" prefWidth="100.0" spacing="20.0" 
  xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"&gt;
  
  &lt;children&gt;
    &lt;Button mnemonicParsing="false" text="Button" /&gt;
    &lt;Button mnemonicParsing="false" text="Button" /&gt;
    &lt;Button mnemonicParsing="false" text="Button" /&gt;
  &lt;/children&gt;
    &lt;opaqueInsets&gt;
      &lt;Insets /&gt;
    &lt;/opaqueInsets&gt;
  &lt;padding&gt;
    &lt;Insets top="20.0" /&gt;
  &lt;/padding&gt;
  &lt;/VBox&gt;
  </code></pre>