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

[TableView] Implement different cell selection behaviour for TableView

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx
    • windows, osx, linux, JDK 8 update 20

      I have a TableView and I set cell selection enabled and set selection mode to multiple. There are at least two columns.

      If I am in the first column with the first cell selected and I hold down shift and then press down a few times then the cells are selected as expected. However if I now press right (still holding shift down) the cell to the right is added to the selection but the cells above this in the second column aren't selected.

      This surprised me as this is the behaviour I would expect and is the default in Excel and JTable

      EDIT:

      If you run the code provided and then:

      1) Click on a cell in the first column
      2) Hold down shift and press the down button a few times
      3) Whilst still holding shift press the right button once

      Notice that you get an "L" shape selection whereas I would expect to get a rectangle selection (see attached screen shots).

      OK, I can't seem to upload attachments, please see links:

      http://i.imgur.com/bhkYS7k.png - L shaped selection - I think is wrong
      http://i.imgur.com/kDO99rE.png - Rectangle selection - This is what I expect to happen (same as Excel and JTable)


      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyObjectWrapper;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TableTest5 extends Application {
          @Override
          public void start(Stage stage) throws Exception {
              BorderPane borderPane = new BorderPane();
              Scene scene = new Scene(borderPane, 500, 500);
              stage.setScene(scene);

              TableView<Integer> table = new TableView<>();
              table.getSelectionModel().setCellSelectionEnabled(true);
              table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

              ObservableList<Integer> data = FXCollections.observableArrayList();
              for (int i = 0; i < 20; i++) {
                  data.add(i);
              }
              table.setItems(data);

              for (int i = 0; i < 5; i++) {
                  TableColumn<Integer,String> column = new TableColumn<>(Integer.toString(i));
                  column.setCellValueFactory(param -> new ReadOnlyObjectWrapper<>(param.getValue().toString()));
                  table.getColumns().add(column);
              }

              borderPane.setCenter(table);
              stage.show();
          }

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

            Unassigned Unassigned
            ndarcy Nick D'Arcy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: