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

Stage.setMinWidth and Stage.setMinHeight is useless with DPI scaling enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u60
    • javafx
    • x86
    • windows_8

        FULL PRODUCT VERSION :
        java version "1.8.0_60"
        Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
        Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.3.9600]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        Using Lenovo ThinkPad

        A DESCRIPTION OF THE PROBLEM :
        The maximum and minimum sizes of a Stage are never scaled, at any DPI. This renders Stage.setMin/MaxWidth/Height effectively useless.
        For example, it is possible to get Stage.width < Stage.minWidth. So setting minWidth and minHeight to current width and height produce odd result: user still can resize down window.
        Another example is setting maxWidth and maxHeight to specific values (i.e. current Stage size) - Stage size will always be less then specified size.
        Without means to get current DPI scaling used in JavaFX we can't fix this problem even on user code side.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Use application that sets Stage minWidth and minHeight to specific, easy recognizable values (i.e. current stage size, or size of non-resizable control on stage)
        Run application on device with hiDPI display and automatic DPI scaling enabled.
        Try to resize down stage to its minimum size.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Stage resized to size specified by minWidth and minHeight with respect to DPI scaling.
        ACTUAL -
        Stage resized to size specified by minWidth and minHeight in sceen pixels. This usualy results in visualy "broken" layout.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public class WindowsSizeTestApp extends Application {
            @Override
            public void start(final Stage stage) throws Exception {
                stage.setWidth(200);
                stage.setHeight(200);
                stage.show();
                stage.setMinWidth(stage.getWidth());
                stage.setMinHeight(stage.getHeight());
                //Should not be able to resize down window
            }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Use Stage widthProperty and heightProperty ChangeListeners to control current width and height min and max values.
        This workaround produces unacceptable graphic artefacts.

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

                Created:
                Updated:
                Resolved: