2021年1月17日星期日

How to load FXML file in center of BorderPane on Application Startup

How do I load an FXML file and have it appear in the centre of the main view on startup?

 @Override  public void start(Stage primaryStage) throws Exception{      Parent root = FXMLLoader.load(getClass().getResource("Main_Scene.fxml"));      primaryStage.setTitle("MY APP");        BorderPane mainPane = FXMLLoader.load(getClass().getResource("Options.fxml"));      mainPane.setCenter();      primaryStage.setScene(new Scene(root, 1024 , 768));      primaryStage.show();  }      public static void main(String[] args) { launch(args); }  

UPDATE: I've done it this way and it seems to work.

 Pane view = FXMLLoader.load(getClass().getResource("SelectPayment.fxml"));      Pane view2 = FXMLLoader.load(getClass().getResource("Options.fxml"));      mainPane = new BorderPane();      mainPane.setLeft(view);      mainPane.setCenter(view2);        primaryStage.setScene(new Scene(mainPane, 1024 , 768));      primaryStage.show();  
https://stackoverflow.com/questions/65766931/how-to-load-fxml-file-in-center-of-borderpane-on-application-startup January 18, 2021 at 07:09AM

没有评论:

发表评论