JDK-8192800 : Table auto resize ignores column resize policy
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8,9,10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2017-11-29
  • Updated: 2020-01-31
  • Resolved: 2018-03-20
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.
JDK 8 Other
8u192Fixed openjfx11Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_162-ea"
Java(TM) SE Runtime Environment (build 1.8.0_162-ea-b03)
Java HotSpot(TM) Client VM (build 25.162-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The auto-resize of a column should do its best to work within the constraints placed on the table itself.  Now, the auto resize (which is a great feature!) works unconstrained by the column resize policy.  Later, when the resize policy is again enforced, the columns really jump around in a way that would not be expected by a user.

I identified this issue in a previous version of the JRE, but am submitting it under the most recent one I can find.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
 Double click in the header between the description and last name to resize the column to fit the content.  Even though the columns are constrained to fit the overall table, this is ignored.  Manually resizing any column will put the table back into the appropriate state.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Column would resize as best it could, given the resize policy.
ACTUAL -
Column is resized, ignoring the resize policy.  Then, when another resize occurs, the resize policy is enforced again in a way that would be jarring to a user.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package tableviewresize;

import javafx.application.Application;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class TableViewResize extends Application {

    @Override
    public void start(Stage primaryStage) {

        TableView<TableObject> table = new TableView<>();
        TableColumn<TableObject, String> column;
        column = new TableColumn<>("First Name");
        column.setCellValueFactory((d) -> d.getValue().firstNameProperty);
        table.getColumns().add(column);

        column = new TableColumn<>("Description");
        column.setCellValueFactory((d) -> d.getValue().descriptionProperty);
        table.getColumns().add(column);

        column = new TableColumn<>("Last Name");
        column.setCellValueFactory((d) -> d.getValue().lastNameProperty);
        table.getColumns().add(column);

        table.getItems().add(new TableObject("John", "Doe", "Currently wearing brown pants"));
        table.getItems().add(new TableObject("John", "Doe", "Currently wearing brown pants"));
        table.getItems().add(new TableObject("John", "Doe", "Currently wearing brown pants"));
        table.getItems().add(new TableObject("John", "Doe", "Currently wearing brown pants"));
        table.getItems().add(new TableObject("John", "Doe", "Currently wearing brown pants"));

        table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

        BorderPane root = new BorderPane();
        Label label = new Label("Double click in the header between the description and last name to resize the column to fit the content.  "
                + "Even though the columns are constrained to fit the overall table, this is ignored.  Manually resizing any column will "
                + "put the table back into the appropriate state.");
        label.setWrapText(true);

        table.setStyle("-fx-font-size: 130%");
        label.setStyle("-fx-font-size: 125%");

        root.setTop(label);
        root.setCenter(table);
        Scene scene = new Scene(root, 450, 350);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    private static final class TableObject {

        private final SimpleObjectProperty<String> firstNameProperty;
        private final SimpleObjectProperty<String> lastNameProperty;
        private final SimpleObjectProperty<String> descriptionProperty;

        public TableObject(String firstName, String lastName, String description) {
            this.firstNameProperty = new SimpleObjectProperty<>(firstName);
            this.lastNameProperty = new SimpleObjectProperty<>(lastName);
            this.descriptionProperty = new SimpleObjectProperty<>(description);
        }
    }

}

---------- END SOURCE ----------


Comments
Approved to backport to 8u-dev for 8u192.
21-04-2018

+1
21-04-2018

Updated patch: added delay to tests http://cr.openjdk.java.net/~pkbalakr/fx/8192800/8u/webrev.03/
20-04-2018

I would be OK with your adding a sleep for now, since that fixes the problem on my system and is less intrusive. Perhaps a better solution would be to run it using "Util.runAndWait", but even then you still might need a sleep since layout can take time to complete. In any case, we can add this to the list of window-based tests to clean up when we address JDK-8176884.
19-04-2018

I reran the tests and it still fails for me about 1/3 of the time. I put in some debugging print statements and it looks like the posX and posY are being calculated incorrectly when it fails. This suggests that the layout has not yet been done when the test reads the values. Looking at this more closely, the real problem might be that the test is not thread safe, since it reads the values computed by layout in the test thread rather than the FX application thread. Another data point is that if I add a "sleep(1000)" at the beginning of the test method (before reading any of the state) it seems to work reliably for me.
19-04-2018

Update: Executed tests on Ubuntu 16.04 several times. Tests passed always.
19-04-2018

Updated patch as per review comments: http://cr.openjdk.java.net/~pkbalakr/fx/8192800/8u/webrev.02/ Executed tests on Mac, Windows and Ubuntu 14.04 several times (20+). Test passed always. Can you specify which Linux OS version.
16-04-2018

1. Trailing whitespace in TableViewResizeColumnToFitContentTest.java 2. Please add exclusion for 'test/robot/**' to build.gradle in !IS_USE_ROBOT block so that the test will be propertly excluded when USE_ROBOT is false. 3. The package statement is wrong in TreeTableViewResizeColumnToFitContentTest package test.javafx.robot.scene.treetableview; it should be: package test.robot.javafx.scene.treetableview; Also, while testing I saw some intermittent failures with the new tests (6 total test failures out of 10 runs each (20 runs total) = 30% failure rate) on my Linux box. Not sure what to make of this. Have you run the test on multiple platforms? How many times?
12-04-2018

8u-backport review request : http://cr.openjdk.java.net/~pkbalakr/fx/8192800/8u/webrev.01/
12-04-2018

http://hg.openjdk.java.net/openjfx/jfx-dev/rt/rev/f82a2e491b72 changeset 10873:f82a2e491b72 8192800: Table auto resize ignores column resize policy Reviewed-by: kcr author pkbalakr
20-03-2018

The code change looks fine, but you still haven't fixed the whitespace issues. +1 pending the whitespace fixes (no need for a new webrev providing that whoever pushes it runs "hg jcheck" first)
09-03-2018

Hi Kevin, Thank you for the review. Please review updated patch. http://cr.openjdk.java.net/~pkbalakr/fx/8192800/webrev.04/
09-03-2018

The fix looks fine to me with two comments: 1. You still have trailing whitespace that needs to be removed from one of the tests. You can use tools/scripts/checkWhiteSpace to both detect and fix, if you like (or use your IDE to remove trailing whitespace). 2. The modified code checks for a non-zero width of the table view / tree table view: 143 if (tv.getColumnResizePolicy() == TableView.CONSTRAINED_RESIZE_POLICY && tv.getWidth() != 0) { ... 229 if (ttv.getColumnResizePolicy() == TreeTableView.CONSTRAINED_RESIZE_POLICY && ttv.getWidth() != 0) { Can the width ever be negative, either because it uses a negative value as out-of-band (e.g., we use "-1" in some places to indicate an invalid size), or due to rounding error? If so, then a test for "> 0" might be safer. Maybe this case can't happen, but testing floating point values using an equality check needs to be done carefully.
09-03-2018

updated: removed whitespace http://cr.openjdk.java.net/~pkbalakr/fx/8192800/webrev.03/
31-01-2018

I'll review it soon, but I did notice one thing that needs to be fixed: jcheck reports the following error: Extraneous text in comment tests/system/src/test/java/test/robot/javafx/scene/tableview/TableViewResizeColumnToFitContentTest.java:75: Trailing whitespace
30-01-2018

Hi Prem, The change looks good to me, +1.
29-01-2018

Hi Ambarish, Thank you for the review. Please review updated patch, i have handled nested columns resize issue. http://cr.openjdk.java.net/~pkbalakr/fx/8192800/webrev.02/
29-01-2018

Hi Prem, Thanks for the updating the fix, As we discussed about HelloTableView app, please check the behavior of resizing a column having lengthy text & nested columns.
12-01-2018

Thank you for the review. I have updated patch as per review comments and fix for TreeTableView. http://cr.openjdk.java.net/~pkbalakr/fx/8192800/webrev01/
11-01-2018

Hi Prem, The fix looks good to me. I have some additional suggestions, 1. In the test, [Line 49] In the test description there is a small typo. Change "Test to verifying TableView..." to "Test to verify TableView..." 2. In the test, second asserTrue() statement [Line-100], can be replaced with assertEquals() 3. Is similar fix change required for TreeTableView inside the method ? private static <T,S> void resizeColumnToFitContent(TreeTableView<T> ttv, TreeTableColumn<T,S> tc, TableViewSkinBase tableSkin, int maxRows) {...}
09-01-2018

cause: resize column to fit content ignores column resize policy set. Fix: resize policy set is honoured. http://cr.openjdk.java.net/~pkbalakr/fx/8192800/webrev.00/
08-01-2018

Issue reproducible with JDK10-ea+33 on Windows 7
01-12-2017

Based on 'steps to reproduce', double clicking the header between the description and last name to resize the column, increases the table size and horizontal scrollbar becomes visible. Manually resizing the columns, put back the table in previous size and horizontal scrollbar also goes off. According to TableView.CONSTRAINED_RESIZE_POLICY : Simple policy that ensures the width of all visible leaf columns in this table sum up to equal the width of the table itself. https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html#CONSTRAINED_RESIZE_POLICY Above behavior is same in 8u60 8u162-b03, 9.0.1 and 10-ea+32 (Windows 10 / Ubuntu 16.04.2 LTS).
30-11-2017

Target to 11, but we should consider this for 10 if there is time.
30-11-2017