gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:18 24 4
gpt4 key购买 nike

我加载它的第一阶段总是以全屏模式正确打开。

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

但是当我更改为另一个 FXML 时,应用程序保持全屏(没有顶部工具栏..),但实际 View 内容的大小会根据 FXML 的根 AnchorPane 的 prefWidth/prefHeight 进行调整(我可以在右下角看到桌面角落 :|),我希望它能够根据我的屏幕分辨率动态变化。

谢谢。

@稍后编辑:

因此,在我的主类的启动方法上,我加载了一个场景(从 FXML 文档创建)并将其设置为舞台(启动方法参数)。我保存这个阶段以备后用。

当我按下与之前保存的相同阶段的按钮时,我将场景更改为另一个 FXML 文档

@截图:

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 - 重新加载第二个场景后 - 下面的示例 Controller 类代码

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

关于java - 全屏阶段在 JavaFX 2.1 中无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11273378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com