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

Stack overflow when Windows scale setting is changed when binded to stage height

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Tested on Windows 10

      Java JDK 24-ea+19
      JavaFX 24-ea+13

      A DESCRIPTION OF THE PROBLEM :
      When the stage.minHeightProperty() is binded to stage.heightProperty() and stage.getScene().heightProperty(), a stack overflow will likely happen if the Windows "Display > Scale and layout > Change the size of text, apps and other items" is changed with the application open.

      The purpose of binding to those properties is to account for the title bar height when setting the stage min height.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the source code.
      2. Resize the window to the minimum size.
      3. In Windows Settings, change the "Display > Scale and layout > Change the size of text, apps and other items" setting to a new higher value.
      3. Repeat previous step if needed, this issue should reproduce within a few attempts.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The window is scaled using the new percentage value.
      ACTUAL -
      A stack overflow occurs, the window height exceeds the screen height.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.CornerRadii;
      import javafx.scene.layout.StackPane;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;

      public class HelloFX extends Application {

          private Stage stage;

          @Override
          public void start(Stage stage) {
              this.stage = stage;
              String javaVersion = System.getProperty("java.version");
              String javafxVersion = System.getProperty("javafx.version");
              StackPane layout = new StackPane();
              StackPane layout2 = new StackPane();
              layout.getChildren().add(layout2);
              layout.getChildren().add(new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."));
              
              BackgroundFill bf = new BackgroundFill(Color.valueOf("#f00"), new CornerRadii(8), Insets.EMPTY);
              layout2.setBackground(new Background(bf));
              layout2.setMinHeight(500);
              layout2.setMaxHeight(500);
              layout2.setMinWidth(500);
              layout2.setMaxWidth(500);
              Scene scene = new Scene(layout, 500, 500);
              stage.setScene(scene);
              stage.setMinWidth(500);
              stage.minHeightProperty().bind(stage.heightProperty().subtract(scene.heightProperty()).add(500));
              stage.show();
          }

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

      FREQUENCY : often


            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: