Shift+Click to Select Multiple cells in JavaFX TableView hangs


Question

I have a reasonably sized TableView (4000 rows, 3 columns) that is both cell selection enabled and multiple selection enabled. When I click on the first cell in the first column, then Shift + click on the last cell in the last column to select the whole table, my program hangs and eventually crashes.

However, when I use Ctrl+A to select the whole table, there is no problem. Also, if I disable cell selection so rows are selected instead of cells, there also is no hanging.

I'd like to keep cell selection enabled, but the hanging is a big issue, as it's intuitive for users to use Shift+Click to select large sections of data. Is there any improvement I could make to my code to prevent the hanging?

Here's the underlying data model:

public class Person {

   private final StringProperty id = new SimpleStringProperty();
   private final StringProperty firstName = new SimpleStringProperty();
   private final StringProperty lastName = new SimpleStringProperty();

   public Person(String id, String firstName, String lastName) {
      this.id.set(id);
      this.firstName.set(firstName);
      this.lastName.set(lastName);
   }

   public StringProperty idProperty() {
      return id;
   }

   public StringProperty firstNameProperty() {
      return firstName;
   }

   public StringProperty lastNameProperty() {
      return lastName;
   }
}

And here's the table code:

  final TableView<Person> table = new TableView<Person>();
  table.setItems(viewModel.personList());

  TableColumn<Person, String> idColumn = new TableColumn<Person, String>("ID");
  idColumn.setCellValueFactory(new PropertyValueFactory<Person, String>("id"));

  TableColumn<Person, String> firstNameColumn = new TableColumn<Person, String>(
           "First Name");
  firstNameColumn.setCellValueFactory(new PropertyValueFactory<Person, String>(
              "firstName"));

  TableColumn<Person, String> lastNameColumn = new TableColumn<Person, String>(
        "Last Name");
  lastNameColumn.setCellValueFactory(new PropertyValueFactory<Person, String>(
              "lastName"));

  table.getColumns().add(idColumn);
  table.getColumns().add(firstNameColumn);
  table.getColumns().add(lastNameColumn);

  table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

  table.getSelectionModel().setCellSelectionEnabled(true);
  table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
1
4
10/14/2013 10:22:18 PM

tblView.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                tblView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
            }
        });
6
8/15/2015 9:33:42 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon