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

TableView selection gets partly lost when the last element of the selected item is deleted

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      This has originally been tested with
      * Oracle JDK 8 (Update 281) on Windows 7 and 10.

      This behaviour also has been reproduced with:
      * Oracle JDK 15.0.2 using Java FX 15.0.1
      * Oracle JDK 17 (EA build 11) using Java FX 17-ea+2


      A DESCRIPTION OF THE PROBLEM :
      When programmatically deleting the downmost of several selected rows from a TableView the selection is party lost. All but one row become deselected. This does not happen if other selected rows are being deleted.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Start the given program.
      2) Press button "C: Remove row at index 3"


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After step 2 the selection of the tableview should contain the following rows:
      row-1
      row-2

      ACTUAL -
      But instead only the following rows are selected:
      row-2


      ---------- BEGIN SOURCE ----------
      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.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

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

        @Override
        public void start(Stage primaryStage) throws Exception {
          TableView<String> tablePane = new TableView<>();
          tablePane.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          TableColumn<String, String> column = new TableColumn<>("Text");
          column.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()));
          tablePane.getColumns().add(column);
          Button buttonA = new Button("A: Remove row at index 1");
          Button buttonB = new Button("B: Remove row at index 2");
          Button buttonC = new Button("C: Remove row at index 3");
          HBox hbox = new HBox(buttonA, buttonB, buttonC);
          BorderPane root = new BorderPane();
          root.setTop(hbox);
          root.setCenter(tablePane);
          Scene scene = new Scene(root);
          primaryStage.setScene(scene);
          primaryStage.show();

          String[] row = new String[5];
          for (int index = 0; index < row.length; ++index) {
            row[index] = "row-" + index;
          }
          tablePane.getItems().add(row[0]);
          tablePane.getItems().add(row[1]);
          tablePane.getItems().add(row[2]);
          tablePane.getItems().add(row[3]);
          tablePane.getItems().add(row[4]);
          tablePane.getSelectionModel().selectIndices(1, 2, 3);

          buttonA.setOnAction(e -> {
            tablePane.getItems().remove(1);
          });
          buttonB.setOnAction(e -> {
            tablePane.getItems().remove(2);
          });
          buttonC.setOnAction(e -> {
            tablePane.getItems().remove(3);
          });
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Replace the buttonC action with the following code:

      buttonC.setOnAction(e -> {
            tablePane.getSelectionModel().selectIndices(1, 2);
            tablePane.getSelectionModel().clearSelection(3);
            tablePane.getItems().remove(3);
      });


      FREQUENCY : always


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

              Created:
              Updated: