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

Stage.setMaximized(true) does not work properly at Application startup

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      Java8 ea-102 on MS-Windows Seven.

      Description

      It seems stage.setMaximized(true) is taken into account only after actual on-screen rendering.
      The following test code works as-is, but it contains *two* workarounds that should not be necessary:
      1) delays SplitPane.setDividerPositions() to after actual scene rendering.
      2) forces layout via SplitPane.layout().
      The first is absolutely necessary because without it setDividerPositions() is applied to a very small window and fails to properly set dimensions, while the second has "interesting effects": if removed resize will happen only for "root" and only after you click on a divider.

      I reported this malfunction also to RT-10376, but I was instructed to "file a separate request"; I hope this is what was meant (it's the first time I use Jira, please bear with me).

      ================================================
      import java.util.Timer;
      import java.util.TimerTask;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.geometry.Orientation;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.SplitPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class Main extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception {
      final SplitPane root = new SplitPane();
      root.setOrientation(Orientation.VERTICAL);
      final SplitPane child;

      {
      {
      child = new SplitPane();
      child.setDividerPositions(0.3);
      {
      HBox h = new HBox();
      h.getChildren().add(new Label("LEFT"));
      child.getItems().add(h);
      }
      {
      HBox h = new HBox();
      h.getChildren().add(new Label("RIGHT"));
      child.getItems().add(h);
      }
      root.getItems().add(child);
      }
      {
      HBox bottom = new HBox();
      bottom.getChildren().add(new Label("Bottom"));
      root.getItems().add(bottom);
      }
      }
      root.setDividerPositions(0.8);

      Scene s = new Scene(root);
      primaryStage.setScene(s);
      primaryStage.setMaximized(true);

      Timer timer = new Timer(true);
      timer.schedule(new TimerTask() {
      @Override
      public void run() {
      Platform.runLater(new Runnable() {
      @Override
      public void run() {
      child.setDividerPositions(0.3);
      child.layout(); // fixed by forcing a relayout!!!
      root.setDividerPositions(0.8);
      }
      });
      }
      }, 1000);

      primaryStage.show();
      }
      }
      ================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mcondareljfx Mauro Condarelli (Inactive)
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported: