Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8322252 | jfx17.0.10 | Jose Pereda | P3 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
Tested on Java 11 / 16 / 17 / 18 (Linux and Windows 10/11) and JavaFX 11, 16, 18 and 19
A DESCRIPTION OF THE PROBLEM :
Hello,
I found out a problem and inconsistent behavior with setScene(...) method on stages.
If the setScene(...) method is called on a stage when uiScale > 1, then the scene components are not layed out correctly (they are "out of bounds"). I think this is because the returned scene width/height are incorrect after a second setScene(...) call (with and height are higher than before, even if the stage size didn't change).
If the stage is manually resized, the content is correctly layout out.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Have a uiScale > 1.0 on the system.
1. Create a stage and set a scene inside
2. Show this stage
3. Create a new scene and set the scene to the stage
4. The newly created scene is not displayed correctly
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The newly created/set scene should be displayed correctly (its size should be the same than previous scene)
ACTUAL -
The newly created/set scene has wrong dimensions.
The returned width/height are incorrect : they are computed as if the uiScale = 1.0 so the scene is not correctly displayed
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ProblemSetSceneHighDPI extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.setScene(createScene("This is centered"));
primaryStage.show();
new Thread(() -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Scene nScene = createScene("This is NOT centered");
Platform.runLater(() -> primaryStage.setScene(nScene));
}).start();
}
private Scene createScene(String text) {
VBox box = new VBox(new Label(text));
box.setAlignment(Pos.CENTER);
return new Scene(box);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
- User should resize the stage
- Resize the stage with API
These two methods are not great as they are directly impacting UI showed to user.
FREQUENCY : always
Tested on Java 11 / 16 / 17 / 18 (Linux and Windows 10/11) and JavaFX 11, 16, 18 and 19
A DESCRIPTION OF THE PROBLEM :
Hello,
I found out a problem and inconsistent behavior with setScene(...) method on stages.
If the setScene(...) method is called on a stage when uiScale > 1, then the scene components are not layed out correctly (they are "out of bounds"). I think this is because the returned scene width/height are incorrect after a second setScene(...) call (with and height are higher than before, even if the stage size didn't change).
If the stage is manually resized, the content is correctly layout out.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Have a uiScale > 1.0 on the system.
1. Create a stage and set a scene inside
2. Show this stage
3. Create a new scene and set the scene to the stage
4. The newly created scene is not displayed correctly
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The newly created/set scene should be displayed correctly (its size should be the same than previous scene)
ACTUAL -
The newly created/set scene has wrong dimensions.
The returned width/height are incorrect : they are computed as if the uiScale = 1.0 so the scene is not correctly displayed
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ProblemSetSceneHighDPI extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setWidth(800);
primaryStage.setHeight(600);
primaryStage.setScene(createScene("This is centered"));
primaryStage.show();
new Thread(() -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Scene nScene = createScene("This is NOT centered");
Platform.runLater(() -> primaryStage.setScene(nScene));
}).start();
}
private Scene createScene(String text) {
VBox box = new VBox(new Label(text));
box.setAlignment(Pos.CENTER);
return new Scene(box);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
- User should resize the stage
- Resize the stage with API
These two methods are not great as they are directly impacting UI showed to user.
FREQUENCY : always
- backported by
-
JDK-8322252 Second call to Stage.setScene() create sizing issue with uiScale > 1.0
- Resolved
- duplicates
-
JDK-8199204 Scene set after stage shown is not sized correctly with HiDPI scaling
- Closed
- relates to
-
JDK-8306121 Scene not rendered initially when changing scenes after fix for JDK-8296621
- Resolved
- links to
-
Commit openjdk/jfx17u/7a4fff07
-
Commit openjdk/jfx/4051f161
-
Review openjdk/jfx17u/171
-
Review openjdk/jfx/1054
(2 links to)