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

Size-restricted window can be observed with incorrect dimensions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • jfx21
    • jfx19
    • javafx
    • None

      On Windows, a `Stage` that is restricted by minimum and maximum sizes can briefly be observed to appear with incorrect dimensions when it is first shown.

      Visually, this can manifest in incorrect window dimensions (see frame1a.jpg) or incorrect `Scene` dimensions (see frame1b.jpg) for the first few frames of the window opening animation. After a few frames, the window is rendered correctly (see frame2.jpg).

      Programmatically, the bug can be observed when the current window size is queried from `Window.onShowing` and `Window.onShown` event handlers.

      Here is a test program:

          @Override
          public void start(Stage stage) {
              var root = new BorderPane();
              var rect1 = new Rectangle(20, 20, Color.BLUE);
              root.setRight(rect1);
              var rect2 = new Rectangle(20, 20, Color.GREEN);
              root.setLeft(rect2);
              var rect3 = new Rectangle(20, 20, Color.PURPLE);
              BorderPane.setAlignment(rect3, Pos.BOTTOM_RIGHT);
              root.setBottom(rect3);

              stage.initStyle(StageStyle.DECORATED);
              stage.setMinWidth(300);
              stage.setMinHeight(200);
              stage.setScene(new Scene(root));
              stage.setOnShowing(event -> System.out.println("width on showing: " + stage.getWidth()));
              stage.setOnShown(event -> System.out.println("width on shown: " + stage.getWidth()));
              stage.show();
          }

      This is the output of the program:
          width on showing: NaN
          width on shown: 56.0

      Whereas this is the expected output:
          width on showing: NaN
          width on shown: 300.0

      The root cause of this bug is that the native WinWindow._setBounds method doesn't respect min/max sizes when calculating the window rect.

        1. frame1a.jpg
          frame1a.jpg
          2 kB
        2. frame1b.jpg
          frame1b.jpg
          5 kB
        3. frame2.jpg
          frame2.jpg
          7 kB

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: