JDK-8187899 : Stage doesn't respect its min/max size properties for its initial size
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 9,10
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • CPU: generic
  • Submitted: 2017-09-22
  • Updated: 2021-12-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.15063]

A DESCRIPTION OF THE PROBLEM :
If the min/max size of the stage is set before the stage is shown, the stage won't respect these properties for its initial size. After you move or resize the window, the size adjusts.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached code.
(2. Move or resize the window)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The initial size of the stage should be (600,600) because of the minHeight- and the minWidth-property.
ACTUAL -
The initial size of the stage is (400,400).

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class StageSizeBug extends Application{

    public static void main(String[] args){
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) throws Exception {
        Label label = new Label("initial size of window is (400,400)\n" +
                "->move or resize window\n" +
                "->size of window changes to (600,600)\n" +
                "EXPECTED: initial size should be (600,600)\n" +
                "because of the minHeight- and the minWidth-property of the stage");
        StackPane pane = new StackPane(label);
        Scene scene = new Scene(pane,400,400);
        primaryStage.setScene(scene);

        primaryStage.setMinHeight(600);
        primaryStage.setMinWidth(600);

        //similar problem with
        //primaryStage.setMaxHeight(200);
        //primaryStage.setMaxWidth(200);

        primaryStage.show();

        //workaround: set properties here
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Set the properties after the stage is shown.


Comments
I note that this is a case of the application setting a size larger than the max size (or smaller than the min size) that is also set by the application. The bug does not affect end users resizing the window using the window manager; the min/max sizes are still respected in those cases. Also, there is a workaround: the application can set the size after the stage is shown. As such, I recommend that we defer this to JDK 11.
11-01-2018

I can confirm that this is specific to the Windows platform. The bug does not occur on a HiDPI Mac or Linux platform. It also does not happen on the latest JDK 8u release, 8u152.
22-11-2017

This bug was introduced (or exposed) by the fix for JDK-8146920.
09-10-2017

Assigning to graphics for now. It might end up being a glass or scenegraph bug, in which case I'll reassign.
27-09-2017

Verified in Windows 10 and issue is reproducible in JDK 9, not in JDK 8. Its a regression in JDK 9, introduced at 9-ea+151. JDK results (windows 10) ------------ 8 GA : Pass 8u131 : Pass 8u152 : Pass 9-ea+150 : Pass 9-ea+151 : Fail <======= regression introduced here 9-ea+181: Fail -------------- Stage works correctly with setHeight() and setWidth() but not with min/max properties. In Ubuntu (6.04.2 LTS), this works fine for 9-ea+181.
25-09-2017