I have a stage with these properties

stage = new Stage(StageStyle.DECORATED);
stage.setFullScreen(true);
stage.setFullScreenExitHint("");
stage.setTitle("My App");
stage.getIcons().add(new Image(icon-address));
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("start.fxml"));
fxmlLoader.setController(this);
...
...//and other properties

It is in full screen in this stage. I have a button and each time I click on it , a method of another class is called and the reference of this stage is passed to it.

For example, if I have two classes Start and ButtonClicked

In Start, I have this :

Button.setOnAction(new EventHandler<ActionEvent>() {

     @Override
     public void handle(ActionEvent event) {
          buttonClicked a = new buttonClicked ();
          try {
             a.render(stage);
          } catch (Exception ex) {
             Logger.getLogger(menuController.class.getName())
                                              .log(Level.SEVERE, null , ex);
          }
     }
});

Now, the render method is called and I have the following code inside render :

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("buttonclicked.fxml"));
fxmlLoader.setController(this);//set Controller for our fxml file
loader = fxmlLoader.load();//loader is a stackPane because buttonclick.fxml has stackPane
stage.setScene(new Scene(loader));
stage.setFullScreen(true);
...

The problem is, if user clicks on button, stage become a 1024x700(because i have pictures in start.fxml and buttonclicked.fxml. The size of both the picture is 1024x700

After a moment, it becomes full screen. How can i fix this ?

I want to kill the delay in full screen

Thanks

有帮助吗?

解决方案

Try

stage.getScene().setRoot(loader);

in render method.
By doing this, the creation of a new scene is eliminated. Therefore I guess, some UI related updates and calculations that must be done after the scene has been shown, are also eliminated.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top