全屏阶段在JavaFX 2.1中无法正常工作?

我加载它的第一个阶段总是作为全屏打开。

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

但是,当我更改为另一个FXML时,应用程序保持全屏(没有顶部工具栏..),但实际视图内容在FXML的根AnchorPane的prefWidth / prefHeight上resize(我可以看到我右下角的桌面:| ),我希望它对我的屏幕分辨率是动态的。

谢谢。

@Later编辑:

因此,在我的主要类I的start方法中加载一个Scene(从FXML doc创建)并将其设置为Stage(start方法参数)。 我保存这个阶段供以后使用。

当我按下具有相同阶段的按钮时,我先保存,然后将场景更改为另一个FXML文档

@Screenshots:

http://tinypic.com/r/2079nqb/6 – 第一个场景正常工作 – 来自主类的开始覆盖方法的代码

  @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 – 重新加载第二个场景后 – 来自示例控制器类的下面的代码

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

我不知道真正的原因,但这里有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); } }); } 

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

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

希望它会对你有所帮助。