Skip to content

Commit a394fab

Browse files
author
Jose Pereda
committed
8199592: Control labels truncated at certain DPI scaling levels
Reviewed-by: kcr, arapte
1 parent 2fe8677 commit a394fab

File tree

2 files changed

+111
-6
lines changed

2 files changed

+111
-6
lines changed

modules/javafx.graphics/src/main/java/javafx/stage/Window.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,6 @@ public String getName() {
10801080
// Register pulse listener
10811081
tk.addStageTkPulseListener(peerBoundsConfigurator);
10821082

1083-
if (getScene() != null) {
1084-
SceneHelper.initPeer(getScene());
1085-
peer.setScene(SceneHelper.getPeer(getScene()));
1086-
SceneHelper.preferredSize(getScene());
1087-
}
1088-
10891083
updateOutputScales(peer.getOutputScaleX(), peer.getOutputScaleY());
10901084
// updateOutputScales may cause an update to the render
10911085
// scales in many cases, but if the scale has not changed
@@ -1098,6 +1092,12 @@ public String getName() {
10981092
peerBoundsConfigurator.setRenderScaleX(getRenderScaleX());
10991093
peerBoundsConfigurator.setRenderScaleY(getRenderScaleY());
11001094

1095+
if (getScene() != null) {
1096+
SceneHelper.initPeer(getScene());
1097+
peer.setScene(SceneHelper.getPeer(getScene()));
1098+
SceneHelper.preferredSize(getScene());
1099+
}
1100+
11011101
// Set peer bounds
11021102
if ((getScene() != null) && (!widthExplicit || !heightExplicit)) {
11031103
adjustSize(true);
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package test.javafx.scene;
26+
27+
import com.sun.javafx.PlatformUtil;
28+
import javafx.application.Application;
29+
import javafx.application.Platform;
30+
import javafx.geometry.Insets;
31+
import javafx.geometry.Pos;
32+
import javafx.scene.Node;
33+
import javafx.scene.Scene;
34+
import javafx.scene.control.CheckBox;
35+
import javafx.scene.layout.HBox;
36+
import javafx.scene.text.Text;
37+
import javafx.stage.Stage;
38+
import javafx.stage.WindowEvent;
39+
import junit.framework.Assert;
40+
import org.junit.AfterClass;
41+
import org.junit.BeforeClass;
42+
import org.junit.Test;
43+
44+
import java.util.concurrent.CountDownLatch;
45+
import java.util.concurrent.TimeUnit;
46+
47+
import static org.junit.Assert.fail;
48+
import static org.junit.Assert.assertTrue;
49+
import static org.junit.Assume.assumeTrue;
50+
51+
public class UIRenderSceneTest {
52+
private static CountDownLatch startupLatch;
53+
private static volatile Stage stage;
54+
private static final double scale = 1.75;
55+
56+
public static class TestApp extends Application {
57+
58+
@Override
59+
public void start(Stage primaryStage) throws Exception {
60+
final HBox box = new HBox();
61+
box.setAlignment(Pos.CENTER);
62+
box.setPadding(new Insets(8));
63+
box.setSpacing(8);
64+
65+
for (int i = 0; i < 4; i++) {
66+
box.getChildren().add(new CheckBox("Check"));
67+
}
68+
Scene scene = new Scene(box);
69+
primaryStage.setScene(scene);
70+
stage = primaryStage;
71+
stage.addEventHandler(WindowEvent.WINDOW_SHOWN,
72+
e -> Platform.runLater(startupLatch::countDown));
73+
stage.show();
74+
}
75+
}
76+
77+
@BeforeClass
78+
public static void setupOnce() throws Exception {
79+
System.setProperty("glass.win.uiScale", String.valueOf(scale));
80+
System.setProperty("glass.gtk.uiScale", String.valueOf(scale));
81+
startupLatch = new CountDownLatch(1);
82+
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start();
83+
assertTrue("Timeout waiting for FX runtime to start",
84+
startupLatch.await(15, TimeUnit.SECONDS));
85+
}
86+
87+
@Test
88+
public void testCheckBoxTextDoesNotHaveEllipsis() {
89+
assumeTrue(PlatformUtil.isLinux() || PlatformUtil.isWindows());
90+
91+
Assert.assertEquals("Wrong render scale", scale,
92+
stage.getRenderScaleY(), 0.0001);
93+
94+
for (Node node : stage.getScene().getRoot().getChildrenUnmodifiable()) {
95+
CheckBox box = (CheckBox) node;
96+
Assert.assertEquals("Wrong text", "Check", ((Text) box.lookup(".text")).getText());
97+
}
98+
}
99+
100+
@AfterClass
101+
public static void teardown() {
102+
Platform.runLater(stage::hide);
103+
Platform.exit();
104+
}
105+
}

0 commit comments

Comments
 (0)