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

Stage min/max sizes don't scale with DPI settings

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • 9
    • 8u66
    • javafx
    • x86
    • windows_8

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 (64 bit)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Running at 200% DPI scaling (192 DPI).

      A DESCRIPTION OF THE PROBLEM :
      On Windows, the minimum & maximum size properties of the Stage class don't scale to the current DPI settings, unlike all other drawing coordinates. The explicit size properties (setWidth/setHeight) do scale but setMinWidth, setMaxWidth, setMinHeight & setMaxHeight do not. Any values passed to them are interpreted as unscaled pixels. This causes a mismatch with all other drawing coordinates at DPI settings greater than 125% when the new DPI scaling mechanism of Java SE 8u60 is active.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program under "Source Code". It draws a single window containing a black rectangle surrounded by white margins, and then sets minimum and maximum stage sizes based on the rectangle size. Try resizing the window between minimum and maximum sizes and see what happens.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      At any DPI setting, minimum window size should show the entire black rectangle with thin white margins on all four sides. Maximum window size should then add a lot of white space to the margins.
      ACTUAL -
      At 192 DPI (= 200% of standard), minimum window size shows only a fraction of the black rectangle. Maximum window size shows entire rectangle with thin white margins, i.e. what *should* appear at minimum window size.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;

      public class StageSizeTest extends Application {

          @Override
          public void start(Stage primaryStage) {

              // draw scene-filling rectangle with margin
              final int margin = 10, size = 200;
              Rectangle rect = new Rectangle(margin, margin, size, size);
              StackPane root = new StackPane(rect);
              final int sceneSize = size + 2 * margin;
              Scene scene = new Scene(root, sceneSize, sceneSize);

              // add extra margin for non-client area
              final int stageSize = sceneSize + 3 * margin;
              primaryStage.setMinWidth(stageSize);
              primaryStage.setMinHeight(stageSize);
              primaryStage.setMaxWidth(2 * stageSize);
              primaryStage.setMaxHeight(2 * stageSize);

              primaryStage.setTitle("Stage Size Test");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None, as JavaFX currently does not provide any official way to obtain current DPI scaling.

      Attachments

        Issue Links

          Activity

            People

              flar Jim Graham
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: