-
Bug
-
Resolution: Unresolved
-
P3
-
jfx17
When you scroll to the middle of a grid, and you start editing some cells, the scrollbar content is moving up little by little.
See attached video.
Steps to reproduce:
1) Run this sample:
"
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TableViewRowHeight extends Application {
private TableView<Person> table = new TableView<>();
private final ObservableList<Person> data = FXCollections.observableArrayList();
final HBox hb = new HBox();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
for (int i = 0; i < 100; ++i) {
data.add(new Person("Row " + i));
}
stage.setTitle("Table View Sample");
stage.setWidth(600);
stage.setHeight(800);
table.setEditable(true);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
table.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
@Override
public TableRow<Person> call(TableView<Person> p) {
return new TableRow<Person>() {
@Override
protected double computePrefHeight(double width) {
return getIndex() > 5 ? 150 : 24;
}
};
}
});
table.setItems(data);
table.getColumns().addAll(firstNameCol);
final Button goToCell = new Button("Go to cell 50");
goToCell.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
table.scrollTo(50);
}
});
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
HBox hbox = new HBox(table);
HBox.setHgrow(table, Priority.ALWAYS);
vbox.getChildren().addAll(goToCell, hbox);
VBox.setVgrow(hbox, Priority.ALWAYS);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
public static class Person {
private final SimpleStringProperty firstName;
private Person(String fName) {
this.firstName = new SimpleStringProperty(fName);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
}
}
"
2) Click on the "Go to cell 50" button
3) Double click on cell 52
Actual behavior:
The content is moved little by little toward the top
Expected behavior:
The content stays still.
Explanation:
This is a regression introduced in OpenJFX 17 byJDK-8089589. When we edit a cell, the VirtualFlow is trying to compute an estimated height of the whole content based of a few cell. At each iteration, it adds 2 more cells.
My fifth first cell height are 24px and the rest is 150px. Therefore, each time, the content estimation is growing a little by little, causing the scrollbar content to adjust.
The new API is completely private or package protected, therefore, I do not have any solution or work-around for this issue.
See attached video.
Steps to reproduce:
1) Run this sample:
"
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TableViewRowHeight extends Application {
private TableView<Person> table = new TableView<>();
private final ObservableList<Person> data = FXCollections.observableArrayList();
final HBox hb = new HBox();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
for (int i = 0; i < 100; ++i) {
data.add(new Person("Row " + i));
}
stage.setTitle("Table View Sample");
stage.setWidth(600);
stage.setHeight(800);
table.setEditable(true);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(
new PropertyValueFactory<Person, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
table.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
@Override
public TableRow<Person> call(TableView<Person> p) {
return new TableRow<Person>() {
@Override
protected double computePrefHeight(double width) {
return getIndex() > 5 ? 150 : 24;
}
};
}
});
table.setItems(data);
table.getColumns().addAll(firstNameCol);
final Button goToCell = new Button("Go to cell 50");
goToCell.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
table.scrollTo(50);
}
});
final VBox vbox = new VBox();
vbox.setSpacing(5);
vbox.setPadding(new Insets(10, 0, 0, 10));
HBox hbox = new HBox(table);
HBox.setHgrow(table, Priority.ALWAYS);
vbox.getChildren().addAll(goToCell, hbox);
VBox.setVgrow(hbox, Priority.ALWAYS);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
public static class Person {
private final SimpleStringProperty firstName;
private Person(String fName) {
this.firstName = new SimpleStringProperty(fName);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String fName) {
firstName.set(fName);
}
}
}
"
2) Click on the "Go to cell 50" button
3) Double click on cell 52
Actual behavior:
The content is moved little by little toward the top
Expected behavior:
The content stays still.
Explanation:
This is a regression introduced in OpenJFX 17 by
My fifth first cell height are 24px and the rest is 150px. Therefore, each time, the content estimation is growing a little by little, causing the scrollbar content to adjust.
The new API is completely private or package protected, therefore, I do not have any solution or work-around for this issue.
- relates to
-
JDK-8089589 [ListView] ScrollBar content moves toward-backward during scrolling.
-
- Resolved
-