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

CSS not applied to children if parent removed and then re-added to scene

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u102, 9
    • Fix Version/s: None
    • Component/s: javafx
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows

      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

      A DESCRIPTION OF THE PROBLEM :
      CSS attributes including at least background-color, border-color and border-width are not applied to a child node if its parent is removed from the scene and then re-added.

      When the node is added again then it appears without any of the styles set via "inline" styles i.e. Node.setStyle(). This is also the case when using style-classes and an external stylesheet. The test case attached uses "inline" styles to keep it minimal.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run the test case
      2) Click on the stage
      3) Click on the stage
      4) Click on the stage


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1) Run the test case
      2) Click on the stage <== expect overlay in red with black border, 5px
      3) Click on the stage <== expect overlay to be hidden
      4) Click on the stage <== expect overlay in red with black border, 5px, i.e. same as step 2

      ACTUAL -
      1) Run the test case
      2) Click on the stage <== expect overlay in red with black border, 5px
      3) Click on the stage <== expect overlay to be hidden
      4) Click on the stage <== overlay shown without background or border

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class CssNotApplied extends Application {

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

          @Override
          public void start(Stage primaryStage) throws Exception {
              StackPane topLevel = new StackPane();
              Scene scene = new Scene(topLevel, 400, 300);

              StackPane overlay = new StackPane();
              overlay.setStyle("-fx-background-color: green");

              primaryStage.setScene(scene);
              topLevel.setOnMouseClicked(event -> {
                  HBox box = new HBox(new Label("hello rigby"));
                  box.setStyle("-fx-background-color: red;-fx-border-color:black;-fx-border-width:5px;");
                  overlay.getChildren().setAll(box);
                  
                  // toggle overlay
                  if (!topLevel.getChildren().contains(overlay)) {
                      topLevel.getChildren().add(overlay);
                  } else {
                      topLevel.getChildren().remove(overlay);
                  }
              });
              primaryStage.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Add content to overlay AFTER it has been added to topLevel

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pmangal Priyanka Mangal (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: