简体   繁体   中英

JavaFX Stage Size reset to parent

Switching between scenes; the Parent scene is smaller than the rest of the scenes, so when I go back to the first scene, the stage holds the With/Hight of the last scene. My code to switch to the parent scene is listed below, how can I set it to get the original size of the parent stage/scene? Thanks!!

public void goBack(MouseEvent e) throws IOException {
        Stage stage;
        Parent root;

    root = FXMLLoader.load(getClass().getResource("Main.fxml"));
    stage=(Stage) goBack.getScene().getWindow();
    Scene scene = new Scene(root, 331, 181);
    stage.sizeToScene();
    stage.setScene(scene);
    stage.show();

}

it looks like you are creating a new main scene. Its possible that you are not doing anything with that scene, and that is why nothing appears to be happening. Perhaps instead of doing this you should manually set the scene that already exists back to its original size. Without seeing the entire program I cant say for sure but this is a guess. Note also that it is unneccessary to generate a new main scene all the time. instead when switching scenes, the main scene should simply be set to invisible, until the program navigates back to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM