-
Bug
-
Resolution: Unresolved
-
P4
-
10
To reproduce, run the example below und make sure that the parent of nested columns is not/only partly visible
- click button to scroll to parent of nested columns
- expected: parent column scrolled to leading edge of table
- actual: scrolled such that last column aligned with trailing edge, parent scrolled out to left
Culprit seems to be TableViewSkinBase.scrollHorizontally(targetColumn), in particular its code to calc the horizontal location of the target:
// work out where this column header is, and it's width (start -> end)
double start = 0;
for (TC c : getVisibleLeafColumns()) {
if (c.equals(col)) break;
start += c.getWidth();
}
if col is a parentColumn, the break condition is always false, thus scrolling through to the end.
The example:
public class TableViewNestedScrollHorizontalBug extends Application {
private Parent getContent() {
TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
Locale.getAvailableLocales()));
table.getSelectionModel().setCellSelectionEnabled(true);
TableColumn<Locale, String> countryCode = new TableColumn<>("CountryCode");
countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
TableColumn<Locale, String> language = new TableColumn<>("Language");
language.setCellValueFactory(new PropertyValueFactory<>("language"));
TableColumn<Locale, String> variant = new TableColumn<>("Variant");
variant.setCellValueFactory(new PropertyValueFactory<>("variant"));
TableColumn<Locale, String> display = new TableColumn<>("DisplayName");
display.setCellValueFactory(new PropertyValueFactory<>("displayLanguage"));
TableColumn<Locale, String> nested = new TableColumn<>("Nested");
nested.getColumns().addAll(countryCode, language);
table.getColumns().addAll(display, nested, variant, new TableColumn<>("Dummy"));
Button scrollTo = new Button("ScrollTo Nested");
scrollTo.setOnAction(e -> table.scrollToColumn(nested));
BorderPane pane = new BorderPane(table);
pane.setBottom(scrollTo);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 200, 400));
primaryStage.setTitle(FXUtils.version());
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(TableViewNestedScrollHorizontalBug.class.getName());
}
- click button to scroll to parent of nested columns
- expected: parent column scrolled to leading edge of table
- actual: scrolled such that last column aligned with trailing edge, parent scrolled out to left
Culprit seems to be TableViewSkinBase.scrollHorizontally(targetColumn), in particular its code to calc the horizontal location of the target:
// work out where this column header is, and it's width (start -> end)
double start = 0;
for (TC c : getVisibleLeafColumns()) {
if (c.equals(col)) break;
start += c.getWidth();
}
if col is a parentColumn, the break condition is always false, thus scrolling through to the end.
The example:
public class TableViewNestedScrollHorizontalBug extends Application {
private Parent getContent() {
TableView<Locale> table = new TableView<>(FXCollections.observableArrayList(
Locale.getAvailableLocales()));
table.getSelectionModel().setCellSelectionEnabled(true);
TableColumn<Locale, String> countryCode = new TableColumn<>("CountryCode");
countryCode.setCellValueFactory(new PropertyValueFactory<>("country"));
TableColumn<Locale, String> language = new TableColumn<>("Language");
language.setCellValueFactory(new PropertyValueFactory<>("language"));
TableColumn<Locale, String> variant = new TableColumn<>("Variant");
variant.setCellValueFactory(new PropertyValueFactory<>("variant"));
TableColumn<Locale, String> display = new TableColumn<>("DisplayName");
display.setCellValueFactory(new PropertyValueFactory<>("displayLanguage"));
TableColumn<Locale, String> nested = new TableColumn<>("Nested");
nested.getColumns().addAll(countryCode, language);
table.getColumns().addAll(display, nested, variant, new TableColumn<>("Dummy"));
Button scrollTo = new Button("ScrollTo Nested");
scrollTo.setOnAction(e -> table.scrollToColumn(nested));
BorderPane pane = new BorderPane(table);
pane.setBottom(scrollTo);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(getContent(), 200, 400));
primaryStage.setTitle(FXUtils.version());
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
@SuppressWarnings("unused")
private static final Logger LOG = Logger
.getLogger(TableViewNestedScrollHorizontalBug.class.getName());
}