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

TreeTableView - SelectionModel works incorrect when removing / adding elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u45
    • Fix Version/s: 9
    • Component/s: javafx
    • Labels:
    • Subcomponent:
    • Introduced In Version:
    • CPU:
      x86
    • OS:
      windows_8

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The selection model has information about the current selection:

      - getSelectedIndeces
      - getSelected Index

      If you remove / add Elements, while something is selected in a TreeTableView, the values of getSelectedIndeces and getSelectedIndex are wrong.



      REGRESSION. Last worked in version 8u51

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - select "b" in list
      - press add button
      - press delete button

      Check Syso

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      ADD - Selected Indeces: [2]
      ADD - Selected Index: 2
      Del - Selected Indeces: [2]
      Del - Selected Index: 2

      ACTUAL -
      ADD - Selected Indeces: [2]
      ADD - Selected Index: 2
      Del - Selected Indeces: [1, 2]
      Del - Selected Index: 1


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package de.saxsys.jfx.tabellen;


      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Starter extends Application {



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

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

      Button deleteButton = new Button("del");
      Button addButton = new Button("add");

      TreeTableView<String> tv = new TreeTableView<>();

      tv.setShowRoot(false);
      tv.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

      // ADD DELETE BUG - SELECTED INDECES WRONG
      TreeItem<String> value = new TreeItem<>(new String());
      tv.setRoot(value);
      value.getChildren().addAll(new TreeItem<String>("a"), new TreeItem<String>("b"),
      new TreeItem<String>("c"));

      TreeTableColumn<String, String> col = new TreeTableColumn<>();
      tv.getColumns().addAll(col);
      col.setCellValueFactory((c) -> new SimpleStringProperty(c.getValue().getValue()));

      VBox vBox = new VBox(addButton, deleteButton, tv);

      deleteButton.setOnAction((e) -> {
      TreeItem<String> selectedItem = tv.getSelectionModel().getSelectedItem();
      tv.getRoot().getChildren().remove(selectedItem);
      System.out.println("Del - Selected Indeces: " + tv.getSelectionModel().getSelectedIndices());
      System.out.println("Del - Selected Index: " + tv.getSelectionModel().getSelectedIndex());
      });

      addButton.setOnAction((e) -> {
      Integer index = tv.getSelectionModel().getSelectedIndex();
      tv.getRoot().getChildren().add(index, new TreeItem<>("NEW"));
      System.out.println("ADD - Selected Indeces: " + tv.getSelectionModel().getSelectedIndices());
      System.out.println("ADD - Selected Index: " + tv.getSelectionModel().getSelectedIndex());
      });

      Scene scene = new Scene(vBox);
      stage.setScene(scene);
      stage.show();
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      use getSelectedCells list --> has correct selected elements

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: