0

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.

1 Answers1

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