user1236048
user1236048

Reputation: 5612

Fullscreen stage is not working properly in JavaFX 2.1?

The first stage that I load it always open properly as fullscreen.

stage.setFullScreen(true);
stage.setScene(login_scene); 

But when I change to another FXML the applications stays fullscreen (no top toolbar.. ), but the actual view content gets resized on the prefWidth/prefHeight of the root AnchorPane from FXML (I can see the desktop in my bottom right corner :|), and I want it to be dynamic to my screen resolution.

Thanks.

@Later Edit:

So on the start method of my main Class I load a Scene (created from an FXML doc) and set it to the Stage (the start method param). I save this stage for later use.

When I press a button with the same stage I save previously I change the scene to another FXML document

@Screenshots:

http://tinypic.com/r/2079nqb/6 - 1st scene works normally - code from start override method of the main class

 @Override
  public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));

    stage.setScene(new Scene(root));
    stage.setFullScreen(true);
    stage.show();
    currentStage = stage;
  }

http://tinypic.com/r/szfmgz/6 - after reloading the second scene - the code below from sample controller class

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

Upvotes: 4

Views: 3589

Answers (2)

Rajeev Gupta
Rajeev Gupta

Reputation: 126

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.

Upvotes: 0

Uluk Biy
Uluk Biy

Reputation: 49215

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);
       }
    });
  }

Upvotes: 5

Related Questions