3

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

2 回答 2

5

我不知道真正的原因,但这里有 2 个快速解决方法。
handleButtonAction方法中:
1)不要创建新场景只是替换它的内容

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

2)如果您真的不想创建新场景,请切换全屏

  @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);
       }
    });
  }
于 2012-06-30T12:55:13.500 回答
0

如果我知道您的担忧是正确的,那么您应该将初级阶段用作静态,或者您可以通过制作 getter 和 setter 将其提供给其他控制器。因此,要在同一阶段加载其他 fxml,您可以在加载 fxml 时将其设置为,并确保不要创建另一个场景。因为由于新场景,您实际内容已调整大小。所以你可以使用这个

在 Main.java 中:

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

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

希望它会帮助你。

于 2013-07-29T10:50:17.577 回答