全屏阶段在JavaFX 2.1中无法正常工作? [英] Fullscreen stage is not working properly in JavaFX 2.1?

查看:129
本文介绍了全屏阶段在JavaFX 2.1中无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载它的第一个阶段总是以全屏方式正常打开。

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

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

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

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.

谢谢。

@Later编辑:

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

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.

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

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

@Screenshots:

@Screenshots:

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

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

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


推荐答案

我不知道真正的原因,但这里有2个快速解决方法。

handleButtonAction 方法:

1)不要创建新场景只需替换其内容

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)如果你真的想创造新的场景然后切换全屏

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

这篇关于全屏阶段在JavaFX 2.1中无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆