In this tutorial, there is an example of how to include custom components and use their controllers from the controller of the container.
main_window_content.fxml
<VBox fx:controller="com.foo.MainController">
<fx:include fx:id="dialog" source="dialog.fxml"/>
...
</VBox>
MainController.java
public class MainController extends Controller {
@FXML private Window dialog;
@FXML private DialogController dialogController;
..
If the component is included only once, it works fine. If the same component is included twice, the controllers are not initialized. Both controllers are null.
main_window_content.fxml
<VBox fx:controller="com.foo.MainController">
<fx:include fx:id="dialog1" source="dialog.fxml"/>
<fx:include fx:id="dialog2" source="dialog.fxml"/>
...
</VBox>
MainController.java
public class MainController extends Controller {
@FXML private Window dialog1;
@FXML private DialogController dialogController1;
@FXML private Window dialog2;
@FXML private DialogController dialogController2;
Could someone help me to solve the problem? Thanks
This is my FXML loading code. It is executed in the main application method:
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("main_window_content.fxml"));
stage.setTitle("FXML Welcome");
stage.setScene(new Scene(root, 300, 275));
stage.show();
}