I can't find a clear example of how to write the Main class in the JavaFX application to use the fxml files created in Scene Builder, the part that loads and shows the stage and the scene. Can someone please show me one? I have created 7 different screens and controllers for my application, but the main class has me stumped. This is a different question than just creating the fxml markup in the main class.
Asked
Active
Viewed 1,933 times
0
-
Possible duplicate of [How to load fxml file inside Pane?](http://stackoverflow.com/questions/33748127/how-to-load-fxml-file-inside-pane) – Shekhar Rai Mar 07 '17 at 04:42
-
No, it is not a duplicate, thanks. – Jennifer Chester Mar 07 '17 at 05:26
-
http://stackoverflow.com/documentation/javafx/1580/fxml-and-controllers/5125/example-fxml#t=201703071841446199167 – fabian Mar 07 '17 at 18:42
1 Answers
2
Main class with main method:
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
String fxmlResource = "MainWindow.fxml";
Parent panel;
panel = FXMLLoader.load(getClass().getResource(fxmlResource));
Scene scene = new Scene(panel);
Stage stage = new Stage();
stage.setScene(scene);
stage.show();
}
}

Rinat
- 362
- 3
- 14
-
Thank you this was the perfect answer to my question, I had looked everywhere and you helped me sooooo much, thank you! – Jennifer Chester Mar 08 '17 at 04:15