0

I made an anchorpane with an fxml and a controller. I also made a borderpane with a view, fxml and another controller. How can I add the anchorpane inside the borderpane? The reason I want them in separate fxml and controller is that the borderpane is a lot of code and this would make everything look cleaner.

I thought it would work like this but it doesn't.

Borderfxml:

?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.textfield.*?>

<BorderPane fx:controller="Bordercontroller" xmlns:fx="http://javafx.com/fxml" 
    prefHeight="200" prefWidth="320">

    <top>
    </top>
    <left>
    </left>
    <center>
    </center>
    <right>
        <Anchorpane fx:id="Same id as my anchorpane"/>
    </right>
    <bottom>
    </bottom>

</BorderPane>
Community
  • 1
  • 1
Eric mansen
  • 141
  • 2
  • 15
  • Have a look on [this answer](https://stackoverflow.com/a/29258336/4629012). It could help even if it is not the only possible one. – Pagbo May 29 '18 at 13:29
  • That looks a lot more complicated then I thought it would be. Was hoping it would be a lot simpler. – Eric mansen May 29 '18 at 14:01
  • A controller factory doesn't seem necessary (in the linked question, it is used because the OP wanted to pass parameters to the controllers' constructors). Just use a [``](https://docs.oracle.com/javase/10/docs/api/javafx/fxml/doc-files/introduction_to_fxml.html#include_elements). If you need to access the anchor pane's controller inside the border pane's controller, that is documented [here](https://docs.oracle.com/javase/10/docs/api/javafx/fxml/doc-files/introduction_to_fxml.html#nested_controllers). – James_D May 29 '18 at 14:09
  • True, exactly what you use in your `startpage.fxml` example (from the link) – Pagbo May 29 '18 at 14:16

0 Answers0