FULL PRODUCT VERSION :
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10586]
A DESCRIPTION OF THE PROBLEM :
Initially, TableView.CONSTRAINED_RESIZE_POLICY does not respect the preferred width of the table's columns when it first attempts to ensure internal consistency. Instead, columns appear to get distributed evenly.
On subsequent calls when the table is resized, TableView.CONSTRAINED_RESIZE_POLICY continues to ignore the columns' preferred width UNTIL the user manually resizes one of the columns. Once the user has manually resized one of the columns, subsequent table resizes WILL correctly apply the columns' preferred sizes. This appears to be related to a flaw where the "isFirstRun" flag in CONSTRAINED_RESIZE_POLICY never gets cleared by table resize events--only a column resize will successfully clear the flag.
This makes it impossible to use CONSTRAINED_RESIZE_POLICY when you wish to have columns of different default widths.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using the sample source:
1. Observe the initial column widths.
2. Resize the table.
3. Resize one of the columns, then resize the table.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using the sample source:
1. The columns should initialize to their preferred widths.
2. Because the columns preferred widths are bound to the table width, as the table is resized, the columns should be resized proportionally.
3. Because the columns preferred widths are bound to the table width, resizing the table after manually resizing a column should result in the columns being resized back to their preferred widths.
ACTUAL -
Using the sample source:
1. On initial show, all columns are of the same size; they should not be--their preferred widths are not equal.
2. On resizing the tables, the columns are all resized proportionally, but still all remain the same size despite having different preferred widths.
3. The columns now resize to their desired preferred widths.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TableColumns extends Application
{
private ObservableList<TableTestItem> tableItems = FXCollections.observableArrayList(
new TableTestItem("Alpha", "Echo", "Inda"),
new TableTestItem("Bravo", "Foxtrot", "Juliett"),
new TableTestItem("Charlie", "Golf", "Kilo"),
new TableTestItem("Delta", "Hotel", "Lima"));
@Override
public void start(Stage primaryStage)
{
TableColumn<TableTestItem, String> tableColumn0 = new TableColumn<>("First Column");
tableColumn0.setCellValueFactory(p -> p.getValue().columns.get(0));
TableColumn<TableTestItem, String> tableColumn1 = new TableColumn<>("Second Column");
tableColumn1.setCellValueFactory(p -> p.getValue().columns.get(1));
TableColumn<TableTestItem, String> tableColumn2 = new TableColumn<>("Third Column");
tableColumn2.setCellValueFactory(p -> p.getValue().columns.get(2));
TableView<TableTestItem> table = new TableView<>();
table.getColumns().setAll(tableColumn0, tableColumn1, tableColumn2);
table.setItems(tableItems);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableColumn0.prefWidthProperty().bind(table.widthProperty().multiply(0.20));
tableColumn1.prefWidthProperty().bind(table.widthProperty().multiply(0.50));
tableColumn2.prefWidthProperty().bind(table.widthProperty().multiply(0.30));
Scene scene = new Scene(new VBox(table), 500, 150);
primaryStage.setTitle("Table Column Sizing");
primaryStage.setScene(scene);
primaryStage.show();
}
static class TableTestItem
{
List<StringProperty> columns = new ArrayList<>();
TableTestItem(String column0, String column1, String column2)
{
columns.add(new SimpleStringProperty(column0));
columns.add(new SimpleStringProperty(column1));
columns.add(new SimpleStringProperty(column2));
}
}
}
---------- END SOURCE ----------
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.10586]
A DESCRIPTION OF THE PROBLEM :
Initially, TableView.CONSTRAINED_RESIZE_POLICY does not respect the preferred width of the table's columns when it first attempts to ensure internal consistency. Instead, columns appear to get distributed evenly.
On subsequent calls when the table is resized, TableView.CONSTRAINED_RESIZE_POLICY continues to ignore the columns' preferred width UNTIL the user manually resizes one of the columns. Once the user has manually resized one of the columns, subsequent table resizes WILL correctly apply the columns' preferred sizes. This appears to be related to a flaw where the "isFirstRun" flag in CONSTRAINED_RESIZE_POLICY never gets cleared by table resize events--only a column resize will successfully clear the flag.
This makes it impossible to use CONSTRAINED_RESIZE_POLICY when you wish to have columns of different default widths.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using the sample source:
1. Observe the initial column widths.
2. Resize the table.
3. Resize one of the columns, then resize the table.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Using the sample source:
1. The columns should initialize to their preferred widths.
2. Because the columns preferred widths are bound to the table width, as the table is resized, the columns should be resized proportionally.
3. Because the columns preferred widths are bound to the table width, resizing the table after manually resizing a column should result in the columns being resized back to their preferred widths.
ACTUAL -
Using the sample source:
1. On initial show, all columns are of the same size; they should not be--their preferred widths are not equal.
2. On resizing the tables, the columns are all resized proportionally, but still all remain the same size despite having different preferred widths.
3. The columns now resize to their desired preferred widths.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TableColumns extends Application
{
private ObservableList<TableTestItem> tableItems = FXCollections.observableArrayList(
new TableTestItem("Alpha", "Echo", "Inda"),
new TableTestItem("Bravo", "Foxtrot", "Juliett"),
new TableTestItem("Charlie", "Golf", "Kilo"),
new TableTestItem("Delta", "Hotel", "Lima"));
@Override
public void start(Stage primaryStage)
{
TableColumn<TableTestItem, String> tableColumn0 = new TableColumn<>("First Column");
tableColumn0.setCellValueFactory(p -> p.getValue().columns.get(0));
TableColumn<TableTestItem, String> tableColumn1 = new TableColumn<>("Second Column");
tableColumn1.setCellValueFactory(p -> p.getValue().columns.get(1));
TableColumn<TableTestItem, String> tableColumn2 = new TableColumn<>("Third Column");
tableColumn2.setCellValueFactory(p -> p.getValue().columns.get(2));
TableView<TableTestItem> table = new TableView<>();
table.getColumns().setAll(tableColumn0, tableColumn1, tableColumn2);
table.setItems(tableItems);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableColumn0.prefWidthProperty().bind(table.widthProperty().multiply(0.20));
tableColumn1.prefWidthProperty().bind(table.widthProperty().multiply(0.50));
tableColumn2.prefWidthProperty().bind(table.widthProperty().multiply(0.30));
Scene scene = new Scene(new VBox(table), 500, 150);
primaryStage.setTitle("Table Column Sizing");
primaryStage.setScene(scene);
primaryStage.show();
}
static class TableTestItem
{
List<StringProperty> columns = new ArrayList<>();
TableTestItem(String column0, String column1, String column2)
{
columns.add(new SimpleStringProperty(column0));
columns.add(new SimpleStringProperty(column1));
columns.add(new SimpleStringProperty(column2));
}
}
}
---------- END SOURCE ----------
- blocks
-
JDK-8292810 ☂ CONSTRAINED_RESIZE_POLICY issues
- Resolved
- duplicates
-
JDK-8293119 Additional constrained resize policies for Tree/TableView
- Resolved
- relates to
-
JDK-8089280 horizontal scrollbar should never become visible in TableView with constrained resize policy
- Resolved