Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8160261

Switching scenes don't retain maximized screen in JavaFX

XMLWordPrintable

      FULL PRODUCT VERSION :
      1.8.0_91

      ADDITIONAL OS VERSION INFORMATION :
      MS Windows 10.0.10586

      A DESCRIPTION OF THE PROBLEM :
      I have set up a single primaryStage in which multiple scenes will be switched from one to another and vice versa. Each Scene differs in size. I made my primaryStage.setMaximized(true) and during initialization in hope that the primaryStage always will fit the whole screen. Although the very first scene after initialization of my java app is presented in maximized screen; however the primaryStage will assume the size of the follow-up scenes after it once has been switched to another scene.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected the primaryStage to keep being maximized at all times, regardless of switching scenes.
      ACTUAL -
      primaryStage only keeps the first scene after init to be maximized. After switching scenes, primaryStage will assume the size of the scene it switched to.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;


      public class NewFXMain extends Application {

          @Override
          public void start(Stage primaryStage) {

              // init buttons
              Button btn1 = new Button("switch to next scene >>");
              Button btn2 = new Button("<< switch to previous scene");

              // first rootNode
              StackPane root1 = new StackPane();
              root1.getChildren().add(btn1);
              Scene scene1 = new Scene(root1, 300, 250);

              // second rootNode
              StackPane root2 = new StackPane();
              root2.getChildren().add(btn2);
              Scene scene2 = new Scene(root2, 500, 400);

              // button actions
              btn1.setOnAction((ActionEvent event) -> {
                  primaryStage.setScene(scene2);
              });
              btn2.setOnAction((ActionEvent event) -> {
                  primaryStage.setScene(scene1);
              });

              primaryStage.setMaximized(true);
              primaryStage.setScene(scene1);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      right now I can only try to switch scenes by switching its scenegraph rootNode via primaryStage.getScene().setRoot(<rootNode of another scene>) to keep the primaryStage maximized. The issue with this is the rootNode won't remember which of its childNode previously was being focused, so after switching the rootNode only the very first childNode within the rootNode scenegraph will be focused.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: