JavaFX Nested Controllers (FXML )

Thanks to Daniel (from OTN) I found the error in my code, the names of my controller variables were wrong. They should be <fx:id>Controller.
In other words it should be:

MainController.java

public class MainController extends Controller {
@FXML private Window dialog1;
@FXML private DialogController dialog1Controller;
@FXML private Window dialog2;
@FXML private DialogController dialog2Controller;

But studying the changes introduced in version 2.2 I found that everything can be easily solved by using <fx:root> tag
(like this tutorial).
I entered my component in FXML simply declaring it like this:

<HBox>
    <Dialog id="dialog1" text="Hello World!"/>
    <Dialog id="dialog2" text="Hello World!"/>
</HBox>

I hope to be helpful

Leave a Comment