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

Window width can be sized slightly smaller than Stage.minWidthProperty()

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Tested on Windows 10

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

      A DESCRIPTION OF THE PROBLEM :
      When a Stage min width and min height is set, the window min height will be respected, but the min width will allow at least a few less pixels than what was set as the minimum.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided sample, reduce the window size from the starting size.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The window can not be shrunk any further.
      ACTUAL -
      The width will reduce from 500 pixels to 484.

      ---------- 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 : always


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

              Created:
              Updated: