The example below has a odd row style with a bigger font size. Compile and run:
- expected: column width such that text in all rows fully visible
- actual: text in odd row is eclipsed
Technically, the reason is the cell setup in resizeColumnToFitContent: it's only partially configured by adding to the table but not to a row, thus row styling is not applied.
The example:
public class TableColumnAutoSizing extends Application {
private Parent createContent() {
TableView<String> table = new TableView<>(FXCollections.observableArrayList
("short name", "and now really really longish name that exceeds all"));
TableColumn<String, String> name = new TableColumn<>("Name");
name.setCellValueFactory(cc -> new SimpleStringProperty(cc.getValue()));
table.getColumns().addAll(name);
BorderPane content = new BorderPane(table);
return content;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent(), 400, 200));
//stage.setTitle(FXUtils.version());
URL uri = getClass().getResource("tablecolumnautosizing.css");
stage.getScene().getStylesheets().add(uri.toExternalForm());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
tablecolumnautosizing.css:
/* row styling not taken into accout on autosize
*/
.table-row-cell:odd {
-fx-font-size: 20;
}
- expected: column width such that text in all rows fully visible
- actual: text in odd row is eclipsed
Technically, the reason is the cell setup in resizeColumnToFitContent: it's only partially configured by adding to the table but not to a row, thus row styling is not applied.
The example:
public class TableColumnAutoSizing extends Application {
private Parent createContent() {
TableView<String> table = new TableView<>(FXCollections.observableArrayList
("short name", "and now really really longish name that exceeds all"));
TableColumn<String, String> name = new TableColumn<>("Name");
name.setCellValueFactory(cc -> new SimpleStringProperty(cc.getValue()));
table.getColumns().addAll(name);
BorderPane content = new BorderPane(table);
return content;
}
@Override
public void start(Stage stage) throws Exception {
stage.setScene(new Scene(createContent(), 400, 200));
//stage.setTitle(FXUtils.version());
URL uri = getClass().getResource("tablecolumnautosizing.css");
stage.getScene().getStylesheets().add(uri.toExternalForm());
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
tablecolumnautosizing.css:
/* row styling not taken into accout on autosize
*/
.table-row-cell:odd {
-fx-font-size: 20;
}
- is cloned by
-
JDK-8285197 TableColumnHeader: calc of cell width must respect row styling (TreeTableView)
- Resolved
- relates to
-
JDK-8251481 TableCell accessing row: NPE on auto-sizing
- Resolved
-
JDK-8293778 Initial column autosizing does not take graphics into computing
- Open
-
JDK-8325390 Allow client code to provide a strategy for "fitToColumn" measurement
- Open
(1 links to)