use*_*048 3 java layout javafx fullscreen fxml
我加载它的第一个阶段总是作为全屏打开.
stage.setFullScreen(true);
stage.setScene(login_scene);
Run Code Online (Sandbox Code Playgroud)
但是,当我更改为另一个FXML时,应用程序保持全屏(没有顶部工具栏..),但实际视图内容在FXML的根AnchorPane的prefWidth/prefHeight上调整大小(我可以在右下角看到桌面:| ),我希望它对我的屏幕分辨率是动态的.
谢谢.
@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;
}
Run Code Online (Sandbox Code Playgroud)
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));
}
Run Code Online (Sandbox Code Playgroud)
我不知道真正的原因,但这里有2个快速的解决方法.
在handleButtonAction方法中:
1)不要创建新场景只需替换其内容
@FXML
private void handleButtonAction(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
JavaFXApplication12.currentStage.getScene().setRoot(root);
}
Run Code Online (Sandbox Code Playgroud)
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)