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

TableColumn sometimes ignores it's setPrefWidth() method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u20
    • 8u20
    • javafx
    • Windows 8.1 64 bit, Java 8.0 (public release) and Java 8u20 b13

      Run the following code, which creates a TableView with one column and one empty row.

      import javafx.application.Application;
      import javafx.beans.property.ObjectProperty;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class TableColWidthBug extends Application {
         
         // boilerplate to build table, add it to a stage, and show stage
         public static void main(String[] args) {
             launch(args);
         }
         @Override public void start(Stage primaryStage) {
             StackPane root = new StackPane();
             root.getChildren().add( buildTable() );
             primaryStage.setScene(new Scene(root, 650, 150));
             primaryStage.show();
         }

         private TableView buildTable() {

            // create table with a bunch of column and no rows...
            TableView<Integer> table = new TableView<>();
            TableColumn<Integer, Integer> column = new TableColumn<>("Column");
            table.getColumns().add( column );
            column.setPrefWidth( 150 );
            table.getItems().add(1); // try commenting out this line
               
            return table;
         }
      }

      -------------------

      Note the line where the column's width is set to 150 px.

      If you run the example on the Java 8.0 public release, the column's width is 150 px, as expected. If you comment out the line that adds the row to the table, this has no effect on the column's width.

      But if you run the example on Java 8u20 b13, the column's width is much less that 150 px. It looks like it is being autosized to the width of the header text...? Also, if you comment out the line that adds the row to the table, the problem goes away and the column's width is 150 px as it should be.

            jgiles Jonathan Giles
            cbanackjfx Cory Banack (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: