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

NodeBuilder invalidates system-defined style class

XMLWordPrintable

      When a style class is applied to a node using NodeBuilder#styleClass(), instantiation of the node fails, because NodeBuilder calls getStyleClass().setAll() rather than addAll() to apply the custom style classes. The following example demonstrates the problem:

      NodeBuilderTest.java:

      package test;

      import java.util.Arrays;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.LabelBuilder;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class NodeBuilderTest extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              VBox root = new VBox();
              root.getChildren().add(LabelBuilder.create().text("Hello World").styleClass(Arrays.asList(new String[] {"redLabel"})).build());
              Scene scene = new Scene(root, 640, 480);
              scene.getStylesheets().add("test/node_builder_test.css");
              primaryStage.setScene(scene);
              primaryStage.show();
          }
          
          public static void main(String[] args) {
              launch();
          }
      }

      node_builder_test.css:

      .redLabel {
          -fx-text-fill: #ff0000;
      }


        1. test1.fxml
          0.7 kB
          Jean-Francois Denise

            rbair Richard Bair (Inactive)
            gkbrown Greg Brown (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: