I have been trying to figure out how to use two FXML files and their controllers at the same time in a program, but have found it difficult to find a simple example. Would someone please demonstrate the use of Sample.fxml and Sample1.fxml at the same time, to where both are displayed. If you would be able to demonstrate this in the simplest and easiest possible way for a new Java and JavaFX programer to understand, I would be very great full. Thanks.
Asked
Active
Viewed 108 times
1
-
Possible duplicate of http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml – James_D Apr 23 '14 at 20:23
1 Answers
2
You can solve this problem by adding both the fxml files into a single group, and then you have to add the group to the scene. It is a little more work if you want to make everything look polished, but this the most simple way to do this. Just be sure your controllers are defined in the fxml files.
GridPane root = new GridPane();
root.add((Node)(FXMLLoader.load(getClass().getResource("sample1.fxml"))) , 1 , 1);
root.add((Node)(FXMLLoader.load(getClass().getResource("sample2.fxml"))) , 1 , 2);
primaryStage.setTitle("Two For One Special");
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();

JellyJay
- 401
- 3
- 7