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

TreeTableView's selectedItems may contain null elements instead of being empty

XMLWordPrintable

    • x86_64
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Run the attached code and you'll notice that treeTable.getSelectionModel().getSelectedItems() array contains 3 null elements when there is noting selected in the TreeTableView.


      ---------- BEGIN SOURCE ----------
      package com.test;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TreeTable extends Application {
      public static void main(String[] pArgs) {launch(pArgs);}

      public void start(Stage pStage) {
      final BorderPane pane = new BorderPane();
      final Scene scene = new Scene(pane);
      pStage.setScene(scene);

      TreeTableView<String> treeTable = new TreeTableView<>();
      TreeTableColumn<String,String> col = new TreeTableColumn<>("Column 1");
      col.setCellValueFactory(features -> features.getValue().valueProperty());
      treeTable.getColumns().add(col);
      col = new TreeTableColumn<>("Column 2");
      col.setCellValueFactory(features -> features.getValue().valueProperty());
      treeTable.getColumns().add(col);

      treeTable.setRoot(new TreeItem<>("root"));
      treeTable.setShowRoot(false);
      treeTable.getRoot().getChildren().add(new TreeItem<>("a"));
      treeTable.getRoot().getChildren().add(new TreeItem<>("b"));
      treeTable.getRoot().getChildren().add(new TreeItem<>("c"));

      pane.setCenter(treeTable);
      pStage.show();

      treeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
      treeTable.getSelectionModel().selectAll();

      treeTable.getRoot().getChildren().clear();

      System.out.println("Elements: ");
      for (TreeItem<String> item: treeTable.getSelectionModel().getSelectedItems()) {
      if (item == null) {
      System.out.println("null item");
      } else {
      System.out.println(item.getValue());
      }
      }
      System.out.println();
      }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: