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

[TreeView,TreeTableView] Selection listener is not informed when selected item is removed.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u60
    • Component/s: javafx
    • Labels:
      None

      Description

      This bug can be reproduced using attached application as following:
      1. select 'item1' -> listener on selected items is called
      2. press 'r' (it removes all children) -> listener is not called.
      3. press 'g' (gets the current selection) -> current selection is correct, 'root' in this case.

      Expected behavior -> listener in p. 2 is called.

      import javafx.application.Application;
      import javafx.collections.ListChangeListener;
      import javafx.scene.Scene;
      import javafx.scene.control.MultipleSelectionModel;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeView;
      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyCodeCombination;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Main extends Application {

          private final TreeItem<String> item = new TreeItem<>("child1");

          @Override
          public void start(final Stage primaryStage) throws Exception {
              final VBox box = new VBox();
              final Scene scene = new Scene(box);
              primaryStage.setScene(scene);
              final TreeView<String> treeView = getTreeView();
              box.getChildren().add(treeView);
              primaryStage.show();

              scene.getAccelerators().put(new KeyCodeCombination(KeyCode.R), () -> {
                  treeView.getRoot().getChildren().removeIf(item -> true);
              });
              scene.getAccelerators().put(new KeyCodeCombination(KeyCode.A), () -> {
                  treeView.getRoot().getChildren().add(item);
              });
              scene.getAccelerators().put(new KeyCodeCombination(KeyCode.G), () -> {
                  final MultipleSelectionModel<TreeItem<String>> selectionModel = treeView.getSelectionModel();
                  System.out.println(selectionModel.getSelectedItems());
              });
          }

          private TreeView<String> getTreeView() {
              final TreeItem<String> root = new TreeItem<>("root");
              root.getChildren().add(item);

              final TreeView<String> treeView = new TreeView<String>(root);
              root.setExpanded(true);
              treeView.getSelectionModel().select(root);
              treeView.getSelectionModel().getSelectedItems().addListener((final Change<? extends TreeItem<String>> c) -> {
                  System.out.println(treeView.getSelectionModel().getSelectedItems());
              });
              return treeView;
          }

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

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            tkleszczyjfx Tomasz Kleszczynski (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: