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

[PieChart] adding new data lead to incorrect style classes updating.

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • 8
    • 8
    • javafx
    • 8.0b72

    Description

      Run the code:

          PieChart testedPieChart = new PieChart();
          VBox vb = new VBox();

          @Override
          public void start(Stage stage) throws Exception {

              ObservableList<PieChart.Data> data = FXCollections.<PieChart.Data>observableArrayList();
              for (int i = 0; i < 4; i++) {
                  data.add(new PieChart.Data("Data item " + i, i * 100));
              }
              testedPieChart.setData(data);

              testedPieChart.setTitle("PieChart");
              testedPieChart.setStyle("-fx-border-color: darkgray;");
              testedPieChart.setPrefSize(600, 600);

              Pane pane = new Pane();
              pane.getChildren().add(testedPieChart);

              vb.getChildren().addAll(pane);

              Button printData = new Button("Print");
              printData.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      List<String> styles = new ArrayList<>();
                      recursiveSearch(testedPieChart.getChildrenUnmodifiable(), styles);
                      System.out.println(styles);
                  }

                  private void recursiveSearch(ObservableList<Node> nodes, List<String> styles) {
                      for (Node node : nodes) {
                          if (node instanceof Parent) {
                              recursiveSearch(((Parent) node).getChildrenUnmodifiable(), styles);
                          }
                          for (String str : node.getStyleClass()) {
                              if (str.contains("data")) {
                                  styles.add(str);
                                  System.out.println(node);
                                  break;
                              }
                          }
                      }
                  }
              });

              Button addData = new Button("Add data");
              addData.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      testedPieChart.getData().add(2, new Data("new data", 10));
                  }
              });

              vb.getChildren().addAll(printData, addData);

              pane.setPrefSize(600, 600);

              Scene scene = new Scene(vb, 700, 700);
              stage.setScene(scene);
              stage.show();
          }

      Click "add data" and "print".

      output:
      Region@68d5c08f[styleClass=chart-pie data0 default-color0]
      Region@460847e7[styleClass=chart-pie data1 default-color1]
      Region@6266458b[styleClass=chart-pie data2 default-color2]
      Region@2d2c6ed8[styleClass=chart-pie data3 default-color3]
      Region@22e08e84[styleClass=chart-pie data2 default-color4]
      Region@5015bc46[styleClass=chart-legend-item-symbol chart-pie data0 default-color0 pie-legend-symbol]
      Region@1e2adaa6[styleClass=chart-legend-item-symbol chart-pie data1 default-color1 pie-legend-symbol]
      Region@469d4b24[styleClass=chart-legend-item-symbol chart-pie data2 default-color4 pie-legend-symbol]
      Region@367bbdc6[styleClass=chart-legend-item-symbol chart-pie data2 default-color2 pie-legend-symbol]
      Region@5e2b2b16[styleClass=chart-legend-item-symbol chart-pie data3 default-color3 pie-legend-symbol]
      [data0, data1, data2, data3, data2, data0, data1, data2, data2, data3]

      What we see: there are 2 items "data2" in each, so it becomes not unique. I expect this style class item to be unique.

      Attachments

        Activity

          People

            psomashe Parvathi Somashekar (Inactive)
            akirov Alexander Kirov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: