-
Bug
-
Resolution: Fixed
-
P3
-
8u40
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;
}
}
}
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;
}
}
}