JDK-8199204 : Scene set after stage shown is not sized correctly with HiDPI scaling
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 9,10,openjfx11
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • CPU: generic
  • Submitted: 2018-03-06
  • Updated: 2021-09-30
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 :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7, professional, 64 bit

A DESCRIPTION OF THE PROBLEM :
If the scene is set on the stage AFTER it is shown it is not sized correctly. 

(Background: This was discovered during unit testing with the testFX framework which reuses the same stage for multiple tests with different scenes).

This appears to be a regression. The same code running on Java 8u144 works as expected.

REGRESSION.  Last worked in version 8u151

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
StackPane should fill the window exactly, i.e. the red border should sit just inside the Stage.
ACTUAL -
StackPane appears larger that the stage.
If you resize the stage manually then the StackPane adjusts and is rendered correctly.

REPRODUCIBILITY :
This bug can be reproduced often.

---------- 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 SceneSizeIssue extends Application {

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

    @Override
    public void start(Stage stage) throws Exception {
        stage.setX(50);
        stage.setY(50);
        stage.setWidth(400);
        stage.setHeight(300);

        stage.show();

        StackPane box = new StackPane(new Label("Rigby"));
        box.setStyle("-fx-border-color: red");
        stage.setScene(new Scene(box));

    }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Hide the stage and then show it again


Comments
I see that the problem was introduced in 9b66, & does not reproduce with 9b65. Tested using -Dglass.win.uiScale=1.5
08-03-2018

Attaching screenshot of reproducible test case on JDK 11-ea+3 (Windows 10, 64-bit) - SceenSize_JDK11-ea+3.png
08-03-2018

I note that the following fix went into 9-b66, which might be the cause: JDK-8098184 (Support the Windows 8 APIs that indicate proper scaling for HiDPI screens)
08-03-2018

Another workaround is to resize the window after it is shown.
08-03-2018

I can reproduce this on Windows with HiDPI scaling. [~arapte] Can you try it on a HiDPI system? Alternatively, you can run it with "java -Dglass.win.uiScale=1.5" or similar.
08-03-2018

I looked at the list of changes in FX that went into jdk-9+96 and it seems unlikely that any of them caused this regression.
08-03-2018

I am unable to observe the problem, tested with 9+181 & 10-ea+36 on Windows 7. Could you please provide a screenshot.
07-03-2018

Thank you for the additional information. Ambarish can evaluate it.
07-03-2018

Issue is reproducible and is not duplicate of JDK-8187899 as this issue is regression in JDK 9+96. Also this issue is reproducible in my laptop display and not in connected external monitor. Windows 10, 64-bit JDK results ---------------------------------------- 8b132 : Pass 8u172 : Pass 9+95 : Pass 9+96 : Fail <-- regression inrtoduced here 9.0.4 : Fail 11-ea+03 : Fail ------------------------------------
07-03-2018

Possible duplicate of JDK-8187899 (I will evaluate this).
06-03-2018