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

maximize/minimize window updates getBoundsInLocal() too late

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8u171, openjfx12
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      I've reproduced this on both
               jdk-12 / javafx-sdk-11.0.2
               jre1.8.0_171 (jfxrt.jar)

      A DESCRIPTION OF THE PROBLEM :
      A Rectangle()'s length is adjusted based on the location of two Line()s (a head and tail) in a GridPane(). When resizing the window everything works. When maximizing the getBoundsInLocal() returns the value before the maximize operation and subsequent minimizing ends up returning the value from the maximized window.

      REGRESSION : Last worked in version 11.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program. The window will be empty. Adjust the width and a rectangle will be displayed with a gap of 50 pixels at the right side. Continue adjusting the width of the window and the rectangle is adjusted accordingly. Now maximize the window and the rectangle will not be adjusted. Next, minimize the window and the rectangle will appear without a gap because getBoundsInLocal() is using the maximized value.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The rectangle is always drawn with a gap when maximizing or minimizing the window.
      ACTUAL -
      The rectangle is not sized properly when maximizing and minimizing. Importantly after minimizing it takes several width adjustment on the window for the rectangle to be drawn properly again.

      ---------- BEGIN SOURCE ----------
      /*
       * You must adjust the width of the window for the rectangle to appear.
       * After the rectangle is drawn note that adjusting the window width adjusts
       * width of the rectangle. I've substracted 50 pixels from it's width so that
       * you can distinguish between a correctly size rectangle versus one that
       * extends beyond the right edge of the window.
       *
       * Although newX (see the commented out line) is correct when the window is
       * maximized the call to getBoundsInLocal() is updated too late. The rectangle
       * remains at its prior size. Then when you minimize the rectangle it extends
       * beyond the right edge of the window. I don't know why but it takes several
       * width adjustments for the rectangle to be drawen properly.
       *
       * Of course the same problem exits in the vertical direction (heightProperty())
       */
      import javafx.application.Application;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.Priority;
      import javafx.stage.Stage;
      import javafx.scene.Scene;
      import javafx.scene.shape.Line;
      import javafx.scene.shape.Rectangle;
      import javafx.geometry.Pos;
      import javafx.geometry.HPos;
      import javafx.geometry.VPos;
      import javafx.geometry.Bounds;
      import javafx.beans.value.ObservableValue;
      import javafx.beans.value.ChangeListener;

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

      @Override
      public void start(Stage primaryStage) {

      primaryStage.setTitle("MyTest");
      GridPane root = new GridPane();
      root.setAlignment(Pos.CENTER);

      ColumnConstraints column1 = new ColumnConstraints();
      column1.setHgrow(Priority.ALWAYS);
      root.getColumnConstraints().add(column1);

      Line head = new Line();
      Line tail = new Line();
      Rectangle pipe = new Rectangle();

      GridPane.setHalignment(head, HPos.RIGHT);
      GridPane.setValignment(head, VPos.CENTER);

      GridPane.setHalignment(tail, HPos.LEFT);
      GridPane.setValignment(tail, VPos.CENTER);

      GridPane.setHalignment(pipe, HPos.LEFT);
      GridPane.setValignment(pipe, VPos.CENTER);
      pipe.setWidth(200);
      pipe.setHeight(50);

      root.getChildren().addAll(head, tail, pipe);

      root.widthProperty().addListener(new ChangeListener<Number>() {
      @Override public void changed(ObservableValue<? extends Number>
      observableValue, Number oldX, Number newX) {
      // System.out.println("newX = " + newX);
      Bounds bHead = head.localToScene(head.getBoundsInLocal());
      Bounds bTail = tail.localToScene(tail.getBoundsInLocal());
      pipe.setWidth(bHead.getMinX() - bTail.getMinX() - 50);
      }
      });

      primaryStage.setScene(new Scene(root, 300, 250));
      primaryStage.show();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None known.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                arapte Ambarish Rapte
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: