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

时间:2021-09-01 02:04:10

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.

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

Thanks.

谢谢。

@Later Edit:

@Later编辑:

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.

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

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

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

@Screenshots:

@Screenshots:

http://tinypic.com/r/2079nqb/6 - 1st scene works normally - code from start override method of the main class

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 - after reloading the second scene - the code below from sample controller class

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 个解决方案

#1


5  

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

我不知道真正的原因,但这里有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) If you really nead to create new scene then toggle fullscreen

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

#2


0  

If I am right to know your concern then You should use your primary stage as static or you can make it available to other controller by making getters and setters. So to get same stage to load other fxmls you can set it to when you are loading a fxml and also make sure that do not create another scene. Because due to new scene you actual content resized. So you can use this

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

In Main.java:

在Main.java中:

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

In YourController.java:

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

Hope it will help you.

希望它会对你有所帮助。

#1


5  

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

我不知道真正的原因,但这里有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) If you really nead to create new scene then toggle fullscreen

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

#2


0  

If I am right to know your concern then You should use your primary stage as static or you can make it available to other controller by making getters and setters. So to get same stage to load other fxmls you can set it to when you are loading a fxml and also make sure that do not create another scene. Because due to new scene you actual content resized. So you can use this

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

In Main.java:

在Main.java中:

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

In YourController.java:

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

Hope it will help you.

希望它会对你有所帮助。