Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8237469

Inherited styles don't update when node is moved

    Details

    • Subcomponent:
    • Introduced In Version:
      10
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      When moving a node from one branch of the scene graph to another, under certain circumstances a new style helper will not be created for that node and it will retain styles from when it was in the previous branch.

      The types of styles affected are fonts, inheritable styles such as visibility, and css variables.

      The issue is reproducible following these steps:

      "Create a scenegraph

                       R
               .-----+-----.
               A B
         .----+----.
         C D

      Where C and D are Labels. Then set a font style on A and a different font style on B. C and D should pick up the font style of A. Then move D to B and see if it still has A's font style."

      package test.javafx.scene;

      import com.sun.javafx.css.StyleManager;
      import javafx.stage.Stage;
      import com.sun.javafx.tk.Toolkit;
      import static org.junit.Assert.assertEquals;

      import java.io.IOException;
      import javafx.css.CssParser;
      import javafx.css.Stylesheet;
      import javafx.scene.Scene;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.StackPane;
      import javafx.scene.text.Text;
      import static org.junit.Assert.assertNull;

      import org.junit.Before;
      import org.junit.Test;

      public class CSSStyleHelperTest {

          private Scene scene;
          private Stage stage;
          private StackPane root;

          @Before
          public void setup() {
              root = new StackPane();
              scene = new Scene(root);
              stage = new Stage();
              stage.setScene(scene);

              StyleManager sm = StyleManager.getInstance();
              sm.userAgentStylesheetContainers.clear();
              sm.platformUserAgentStylesheetContainers.clear();
              sm.stylesheetContainerMap.clear();
              sm.cacheContainerMap.clear();
              sm.hasDefaultUserAgentStylesheet = false;
          }

          @Test
          public void movingNodeToDifferentBranchGetsNewFontStyleTest() throws IOException {
              Stylesheet stylesheet = null;
              root.getStyleClass().add("root");
              // R
              // .-----+-----.
              // A B
              // .----+----. .
              // C D E
              //Where C and D are Labels. Then I'd set a font style on A and a different font style on B.
              //C and D should pick up the font style of A. Then move D to B and see if it still has A's
              //font style.
              stylesheet = new CssParser().parse(
                      "movingNodeToDifferentBranchGetsNewFontStyleTest",
                      ".root {}\n"
                      + ".a { -fx-font-style: italic; }\n"
                      + ".b { -fx-font-family: normal; }\n"
              );
              StyleManager.getInstance().setDefaultUserAgentStylesheet(stylesheet);
              Pane A = new Pane();
              A.getStyleClass().add("a");
              Pane B = new Pane();
              B.getStyleClass().add("b");
              Text C = new Text("C");
              Text D = new Text("D");
              Text E = new Text("E");
              root.getChildren().addAll(A, B);
              A.getChildren().addAll(C, D);
              B.getChildren().add(E);
              stage.show();
              Toolkit.getToolkit().firePulse();
              assertEquals("Italic", C.getFont().getStyle());
              assertEquals("Italic", D.getFont().getStyle());
              assertNull(E.getFont().getStyle());

              B.getChildren().add(D); //move D
              Toolkit.getToolkit().firePulse();
              assertEquals("Italic", C.getFont().getStyle());
              assertNull(D.getFont().getStyle());
              assertNull(E.getFont().getStyle());
          }
      }

      The issue appears to have been introduced by https://bugs.openjdk.java.net/browse/JDK-8090462

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dwookey Dean Wookey
                Reporter:
                dwookey Dean Wookey
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: