Fullscreen stage is not working properly in JavaFX 2.1?

好久不见. 提交于 2019-12-01 09:26:42

I have no idea about the real cause but here are 2 quick workarounds.
In the handleButtonAction method:
1) Don't create new scene just replace its content

  @FXML
  private void handleButtonAction(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
    JavaFXApplication12.currentStage.getScene().setRoot(root);
  }

2) If you really nead to create new scene then toggle fullscreen

  @FXML
  private void handleButtonAction(ActionEvent event) throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
    JavaFXApplication12.currentStage.setScene(new Scene(root));
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
           JavaFXApplication12.currentStage.setFullScreen(false);
           JavaFXApplication12.currentStage.setFullScreen(true);
       }
    });
  }
Rajeev Gupta

If I am right to know your concern then You should use your primary stage as static or you can make it available to other controller by making getters and setters. So to get same stage to load other fxmls you can set it to when you are loading a fxml and also make sure that do not create another scene. Because due to new scene you actual content resized. So you can use this

In Main.java:

YourController objYourController  = loader.getController();
objYourController.setDialogStage(primaryStage);

In YourController.java:

public void setMystage(Stage primaryStage) {
    this.primaryStage= primaryStage;
}

//To load another FXML
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
primaryStage.getScene().setRoot(rootLayout);

Hope it will help you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!