Skip to content

Commit 0b74ee8

Browse files
Michael Straußkevinrushforth
authored andcommitted
8290990: Clear .root style class from a root node that is removed from a Scene/SubScene
Reviewed-by: jhendrikx, aghaisas, mhanl
1 parent 7e48413 commit 0b74ee8

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

modules/javafx.graphics/src/main/java/javafx/scene/Scene.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ protected void invalidated() {
12231223

12241224
if (oldRoot != null) {
12251225
oldRoot.setScenes(null, null);
1226+
oldRoot.getStyleClass().remove("root");
12261227
}
12271228
oldRoot = _value;
12281229
_value.getStyleClass().add(0, "root");

modules/javafx.graphics/src/main/java/javafx/scene/SubScene.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ protected void invalidated() {
316316
if (oldRoot != null) {
317317
StyleManager.getInstance().forget(SubScene.this);
318318
oldRoot.setScenes(null, null);
319+
oldRoot.getStyleClass().remove("root");
319320
}
320321
oldRoot = _value;
321322
_value.getStyleClass().add(0, "root");

modules/javafx.graphics/src/test/java/test/javafx/scene/SceneTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -222,6 +222,17 @@ public void testRootUpdatedWhenChangedInScene() {
222222
assertEquals(scene, g2.getScene());
223223
}
224224

225+
@Test
226+
public void testRootStyleClassIsClearedWhenRootNodeIsRemovedFromScene() {
227+
Scene scene = new Scene(new Group());
228+
Group g = new Group();
229+
assertFalse(g.getStyleClass().contains("root"));
230+
scene.setRoot(g);
231+
assertTrue(g.getStyleClass().contains("root"));
232+
scene.setRoot(new Group());
233+
assertFalse(g.getStyleClass().contains("root"));
234+
}
235+
225236
@Test
226237
public void testNodeUpdatedWhenAddedToScene() {
227238
Group root = new Group();

modules/javafx.graphics/src/test/java/test/javafx/scene/SubSceneTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
4141
import javafx.scene.SubSceneShim;
4242
import javafx.scene.layout.Pane;
4343
import static org.junit.Assert.assertEquals;
44+
import static org.junit.Assert.assertFalse;
4445
import static org.junit.Assert.assertNull;
4546
import org.junit.Test;
4647
import static org.junit.Assert.assertTrue;
@@ -131,6 +132,17 @@ public void testRootUpdatedWhenChangedInSubScene() {
131132
assertEquals(subScene, NodeShim.getSubScene(g2));
132133
}
133134

135+
@Test
136+
public void testRootStyleClassIsClearedWhenRootNodeIsRemovedFromSubScene() {
137+
SubScene scene = new SubScene(new Group(), 10, 10);
138+
Group g = new Group();
139+
assertFalse(g.getStyleClass().contains("root"));
140+
scene.setRoot(g);
141+
assertTrue(g.getStyleClass().contains("root"));
142+
scene.setRoot(new Group());
143+
assertFalse(g.getStyleClass().contains("root"));
144+
}
145+
134146
@Test
135147
public void testSetCamera() {
136148
Camera camera = new PerspectiveCamera();

0 commit comments

Comments
 (0)