JDK-8096787 : TableView - multiple selection via shift-click doesn't work with different columns
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-03-20
  • Updated: 2015-06-12
  • Resolved: 2015-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u60Fixed
Description
In a TableView, a shift-click to select multiple items doesn't work if the second click is done on a different column than the first one.


To give you an example, the following code creates a TableView with two columns ("First Name" and "Last Name") and three items ("Person"s with "firstname" and "lastname"-properties).

Since 8u40, if you click on the "firstname" of the first item ("FirstName1") and then try to multi-select all by shift-clicking on the "lastname" of the third item ("LastName3"), all items are unselected instead of being selected.
On the other hand, shift-clicking the "FirstName3" after clicking "FirstName1" does work as intended.


import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
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.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        ObservableList<Person> p = FXCollections.observableArrayList();
        p.add(new Person("FirstName1", "LastName1"));
        p.add(new Person("FirstName2", "LastName2"));
        p.add(new Person("FirstName3", "LastName3"));

        TableView<Person> t = new TableView<>();
        t.setItems(p);
        t.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        TableColumn<Person, String> c1 = new TableColumn<>("First Name");
        c1.setCellValueFactory(new PropertyValueFactory<Person, String>("firstname"));
        TableColumn<Person, String>c2 = new TableColumn<>("Last Name");
        c2.setCellValueFactory(new PropertyValueFactory<Person, String>("lastname"));
        t.getColumns().addAll(c1, c2);

        Scene scene = new Scene(new VBox(t));
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public class Person {

        private final StringProperty firstname = new SimpleStringProperty("");
        private final StringProperty lastname = new SimpleStringProperty("");

        public Person(String firstname, String lastname) {
            this.firstname.set(firstname);
            this.lastname.set(lastname);
        }

        public String getFirstname() {
            return firstname.get();
        }
        public void setFirstname(final String firstname) {
            this.firstname.set(firstname);
        }
        public StringProperty firstnameProperty() {
            return firstname;
        }

        public String getLastname() {
            return lastname.get();
        }
        public void setLastname(final String lastname) {
            this.lastname.set(lastname);
        }
        public StringProperty lastnameProperty() {
            return lastname;
        }
    }
}

Comments
Changeset: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/63ef2254d7d9 Unit tests: javafx.scene.control.TableViewTest.test_rt_40319_toRight_toBottom() javafx.scene.control.TableViewTest.test_rt_40319_toRight_toTop() javafx.scene.control.TableViewTest.test_rt_40319_toLeft_toBottom() javafx.scene.control.TableViewTest.test_rt_40319_toLeft_toTop() javafx.scene.control.TableViewTest.test_rt_40319_toRight_toBottom_useMouse() javafx.scene.control.TableViewTest.test_rt_40319_toRight_toTop_useMouse() javafx.scene.control.TableViewTest.test_rt_40319_toLeft_toBottom_useMouse() javafx.scene.control.TableViewTest.test_rt_40319_toLeft_toTop_useMouse() javafx.scene.control.TreeTableViewTest.test_rt_40319_toRight_toBottom() javafx.scene.control.TreeTableViewTest.test_rt_40319_toRight_toTop() javafx.scene.control.TreeTableViewTest.test_rt_40319_toLeft_toBottom() javafx.scene.control.TreeTableViewTest.test_rt_40319_toLeft_toTop() javafx.scene.control.TreeTableViewTest.test_rt_40319_toRight_toBottom_useMouse() javafx.scene.control.TreeTableViewTest.test_rt_40319_toRight_toTop_useMouse() javafx.scene.control.TreeTableViewTest.test_rt_40319_toLeft_toBottom_useMouse() javafx.scene.control.TreeTableViewTest.test_rt_40319_toLeft_toTop_useMouse()
23-03-2015

I've found the bug, now just working on unit test(s).
23-03-2015

I can reproduce the issue and will look into it for 8u60. For future reference, it would be really appreciated if you can include the entire class code if at all possible - it saves having to create the class, do imports, add the main method, etc. I've updated your code above to what would have been ideal. Thanks!
22-03-2015

I just found https://javafx-jira.kenai.com/browse/RT-39842 , which states the problem as fixed for 8u40, but it's not working for me. edit: It seems, the issue fixed the problem with shift-clicking if CellSelection is enabled, while this happen when CellSelection isn't enabled.
20-03-2015