The key method are situated in TableViewSkin. If you select the right cell or the left cell, only "scrollHorizontally()" will be called. It means that if your selected cell is out of screen, only the Horizontal bar will move. Your cell will still be invisible.
Same thing if your select the next or the previous cell. It will only call "show(index)" on the VirtualFlow. This was maybe though for the row Selection mode because when you select next or previous you don't want to scroll Horizontally. But when in cellSelectionMode, it's kind of weird because if the cell goes out of sight, and if you press key up, only the vertical bar will scroll.
Step to reproduce:
Run this sample:"
public class TableViewSample extends Application {
List<TableColumn<Person, ?>> list = new ArrayList<>();
private TableView<Person> table = new TableView<Person>();
private final ObservableList<Person> data
= FXCollections.observableArrayList(
new Person("Jacob", "Smith", "jacob.smith@example.com"),
new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
new Person("Ethan", "Williams", "ethan.williams@example.com"),
new Person("Emma", "Jones", "emma.jones@example.com"),
new Person("Michael", "Brown", "michael.brown@example.com"));
final HBox hb = new HBox();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
table.getSelectionModel().setCellSelectionEnabled(true);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
for (int i = 0; i < 1000; ++i) {
data.add(new Person("Jacob", "Smith", "jacob.smith@example.com"));
}
addColumns();
table.setItems(data);
Scene scene = new Scene(table);
stage.setTitle("Table View Sample");
stage.setWidth(900);
stage.setHeight(900);
stage.setScene(scene);
stage.show();
}
public void addColumns() {
for (int i = 0; i < 20; ++i) {
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
list.add(firstNameCol);
}
table.getColumns().addAll(list);
}
public static class Person {
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private final SimpleStringProperty email;
private Person(String fName, String lName, String email) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.email = new SimpleStringProperty(email);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String fName) {
lastName.set(fName);
}
public String getEmail() {
return email.get();
}
public void setEmail(String fName) {
email.set(fName);
}
}
} "
Scroll to the right and select a cell.
Scroll back to the left so the selected cell is not visible anymore.
Press arrow down key.
Expected behavior:
The selected cell is visible.
Actual behavior:
The selected cell is not visible, only the vertical scrollbar is moving.
So I suggest adding some "scrollHorizontally()" and some "show(index)" into the "onSelectNextCell", "onSelectPreviousCell" etc etc.
I can provide some more details about the patch if you want.
Same thing if your select the next or the previous cell. It will only call "show(index)" on the VirtualFlow. This was maybe though for the row Selection mode because when you select next or previous you don't want to scroll Horizontally. But when in cellSelectionMode, it's kind of weird because if the cell goes out of sight, and if you press key up, only the vertical bar will scroll.
Step to reproduce:
Run this sample:"
public class TableViewSample extends Application {
List<TableColumn<Person, ?>> list = new ArrayList<>();
private TableView<Person> table = new TableView<Person>();
private final ObservableList<Person> data
= FXCollections.observableArrayList(
new Person("Jacob", "Smith", "jacob.smith@example.com"),
new Person("Isabella", "Johnson", "isabella.johnson@example.com"),
new Person("Ethan", "Williams", "ethan.williams@example.com"),
new Person("Emma", "Jones", "emma.jones@example.com"),
new Person("Michael", "Brown", "michael.brown@example.com"));
final HBox hb = new HBox();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
final Label label = new Label("Address Book");
label.setFont(new Font("Arial", 20));
table.setEditable(true);
table.getSelectionModel().setCellSelectionEnabled(true);
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
for (int i = 0; i < 1000; ++i) {
data.add(new Person("Jacob", "Smith", "jacob.smith@example.com"));
}
addColumns();
table.setItems(data);
Scene scene = new Scene(table);
stage.setTitle("Table View Sample");
stage.setWidth(900);
stage.setHeight(900);
stage.setScene(scene);
stage.show();
}
public void addColumns() {
for (int i = 0; i < 20; ++i) {
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
list.add(firstNameCol);
}
table.getColumns().addAll(list);
}
public static class Person {
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private final SimpleStringProperty email;
private Person(String fName, String lName, String email) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
this.email = new SimpleStringProperty(email);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
public String getLastName() {
return lastName.get();
}
public void setLastName(String fName) {
lastName.set(fName);
}
public String getEmail() {
return email.get();
}
public void setEmail(String fName) {
email.set(fName);
}
}
} "
Scroll to the right and select a cell.
Scroll back to the left so the selected cell is not visible anymore.
Press arrow down key.
Expected behavior:
The selected cell is visible.
Actual behavior:
The selected cell is not visible, only the vertical scrollbar is moving.
So I suggest adding some "scrollHorizontally()" and some "show(index)" into the "onSelectNextCell", "onSelectPreviousCell" etc etc.
I can provide some more details about the patch if you want.