JDK-8130747 : TableView Header is not resized appropriately when TableView is empty
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u45
  • Priority: P5
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-07-06
  • Updated: 2023-01-05
  • Resolved: 2023-01-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Blocks :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The header of a TableView/TreeTableView is not resized correctly when in constrained resize mode and the items of the TableView are cleared. The following will reproduce the problem. The column is not resized with the window after the table is empty.

public class App2 extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(final Stage primaryStage) throws Exception {
    Pane root = new StackPane();

    TableView<String> tableView = new TableView<>();
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    final TableColumn<String, String> column = new TableColumn<>();
    tableView.getColumns().add(column);

    column.setCellValueFactory(param -> new SimpleStringProperty("Hello"));
    final ObservableList<String> items = FXCollections.observableArrayList("1", "2", "3");
    tableView.setItems(items);

    Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(5), event -> items.clear()));
    timeline.play();

    root.getChildren().add(tableView);

    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
}


The problem is within the layoutChildren() method in TableViewSkinBase which does not re-layout the inner VirtualFlow of the table when the TableView is empty. This later leads to problems in the updateContentWidth() method where the width of a column is based on the width of the VirtualFlow which still has its old value.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
Looks like the same issue as JDK-8137244.
26-08-2022

Konstantin Pasko sent the following comment, along with the attached Test2.java test case. ------------------------------------------------------------------- I ran into the same problem as described in https://bugs.openjdk.java.net/browse/JDK-8130747 and I do think it's a bug. I've attached my example to show it more clear. In the begging when the table is empty, the column is being resized with the table. But if we fill the table with some data and then clear it -- it's not resized any more. If we add some data again, the column will be immediately resized. It's the problem for me, because I have the following layout: TABLE | SOME -----------| DETAIL TABLE | VIEW When a row is selected in any table, a detail view should be shown in the animated way. Then it may be closed. The data is coming to the both table and an user can "remove" it from the table. So if I opened the detail view, then one of the table was cleared, then I closed the detail view -- the empty table would be completely retarded (columns headers will not take the whole width of the table). Could you possibly have a look once more at this issue? ----------------------------------------------------------------------
18-09-2015

I don't see what the bug is here. I'm not sure what you expect to happen, but I get the same behavior with a table that is initially empty as when running your program. Jonathan can comment further, but might close this as "Not an issue".
17-07-2015