Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8192800

Table auto resize ignores column resize policy

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Backports

        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 ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  pkbalakr Prem Balakrishnan
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  9 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: