With this sample code based on empty ObservableList, the columns not growing. With two row-items, the columns are growing but threre is a third empty, useless "column" in the table visible.
public void start(Stage primaryStage) throws Exception {
Group rootGroup = new Group();
Scene scene = new Scene(rootGroup, 800, 600);
primaryStage.setScene(scene);
ObservableList<Dimension> testItems = FXCollections.observableArrayList();
//testItems.add(new Dimension(100, 200));
//testItems.add(new Dimension(300, 400));
TableView<Dimension> table = new TableView<Dimension>();
table.setItems(testItems);
TableColumn<String> testColumn = new TableColumn<String>("Width");
testColumn.setResizable(true);
testColumn.setProperty("width");
testColumn.setMinWidth(100);
TableColumn<String> testColumn2 = new TableColumn<String>("Height");
testColumn2.setResizable(true);
testColumn2.setProperty("height");
testColumn2.setMinWidth(100);
table.getColumns().addAll(testColumn, testColumn2);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
BorderPane mainPane = new BorderPane();
mainPane.setCenter(table);
scene.setRoot(mainPane);
primaryStage.centerOnScreen();
primaryStage.setVisible(true);
}
public void start(Stage primaryStage) throws Exception {
Group rootGroup = new Group();
Scene scene = new Scene(rootGroup, 800, 600);
primaryStage.setScene(scene);
ObservableList<Dimension> testItems = FXCollections.observableArrayList();
//testItems.add(new Dimension(100, 200));
//testItems.add(new Dimension(300, 400));
TableView<Dimension> table = new TableView<Dimension>();
table.setItems(testItems);
TableColumn<String> testColumn = new TableColumn<String>("Width");
testColumn.setResizable(true);
testColumn.setProperty("width");
testColumn.setMinWidth(100);
TableColumn<String> testColumn2 = new TableColumn<String>("Height");
testColumn2.setResizable(true);
testColumn2.setProperty("height");
testColumn2.setMinWidth(100);
table.getColumns().addAll(testColumn, testColumn2);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
BorderPane mainPane = new BorderPane();
mainPane.setCenter(table);
scene.setRoot(mainPane);
primaryStage.centerOnScreen();
primaryStage.setVisible(true);
}
- relates to
-
JDK-8137244 Empty Tree/TableView with CONSTRAINED_RESIZE_POLICY is not properly resized
- Resolved