-
Bug
-
Resolution: Fixed
-
P4
-
jfx19
-
None
-
b23
On Windows, a `Stage` that is restricted by minimum and maximum sizes can briefly be observed to appear with incorrect dimensions when it is first shown.
Visually, this can manifest in incorrect window dimensions (see frame1a.jpg) or incorrect `Scene` dimensions (see frame1b.jpg) for the first few frames of the window opening animation. After a few frames, the window is rendered correctly (see frame2.jpg).
Programmatically, the bug can be observed when the current window size is queried from `Window.onShowing` and `Window.onShown` event handlers.
Here is a test program:
@Override
public void start(Stage stage) {
var root = new BorderPane();
var rect1 = new Rectangle(20, 20, Color.BLUE);
root.setRight(rect1);
var rect2 = new Rectangle(20, 20, Color.GREEN);
root.setLeft(rect2);
var rect3 = new Rectangle(20, 20, Color.PURPLE);
BorderPane.setAlignment(rect3, Pos.BOTTOM_RIGHT);
root.setBottom(rect3);
stage.initStyle(StageStyle.DECORATED);
stage.setMinWidth(300);
stage.setMinHeight(200);
stage.setScene(new Scene(root));
stage.setOnShowing(event -> System.out.println("width on showing: " + stage.getWidth()));
stage.setOnShown(event -> System.out.println("width on shown: " + stage.getWidth()));
stage.show();
}
This is the output of the program:
width on showing: NaN
width on shown: 56.0
Whereas this is the expected output:
width on showing: NaN
width on shown: 300.0
The root cause of this bug is that the native WinWindow._setBounds method doesn't respect min/max sizes when calculating the window rect.
Visually, this can manifest in incorrect window dimensions (see frame1a.jpg) or incorrect `Scene` dimensions (see frame1b.jpg) for the first few frames of the window opening animation. After a few frames, the window is rendered correctly (see frame2.jpg).
Programmatically, the bug can be observed when the current window size is queried from `Window.onShowing` and `Window.onShown` event handlers.
Here is a test program:
@Override
public void start(Stage stage) {
var root = new BorderPane();
var rect1 = new Rectangle(20, 20, Color.BLUE);
root.setRight(rect1);
var rect2 = new Rectangle(20, 20, Color.GREEN);
root.setLeft(rect2);
var rect3 = new Rectangle(20, 20, Color.PURPLE);
BorderPane.setAlignment(rect3, Pos.BOTTOM_RIGHT);
root.setBottom(rect3);
stage.initStyle(StageStyle.DECORATED);
stage.setMinWidth(300);
stage.setMinHeight(200);
stage.setScene(new Scene(root));
stage.setOnShowing(event -> System.out.println("width on showing: " + stage.getWidth()));
stage.setOnShown(event -> System.out.println("width on shown: " + stage.getWidth()));
stage.show();
}
This is the output of the program:
width on showing: NaN
width on shown: 56.0
Whereas this is the expected output:
width on showing: NaN
width on shown: 300.0
The root cause of this bug is that the native WinWindow._setBounds method doesn't respect min/max sizes when calculating the window rect.
- relates to
-
JDK-8310845 Size-restricted window reports incorrect dimensions on Linux
- Open
-
JDK-8310846 Skip failing test InitialWindowSizeTest on Linux
- Resolved