Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JavaFx Nested Controllers (FXML <include>)

963770Sep 23 2012 — edited Sep 24 2012
In this tutotial, 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 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();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2012
Added on Sep 23 2012
2 comments
2,849 views