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

|TableView| Columns remain blank after adding rows

    XMLWordPrintable

Details

    Description

      Columns that have been added while there is no rows remain blank after adding rows.
      Manual resizing cause the column to show its content.

      Test code:
      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;
       
      public class NewFXMain extends Application {
       
          private int rows = 0;
          private int cols = 0;
       
          public class TestDataClass {
       
              private final StringProperty testValue;
       
              public TestDataClass() {
                  testValue = new SimpleStringProperty("value");
              }
       
              public TestDataClass(String s) {
                  testValue = new SimpleStringProperty(s);
              }
       
              public String getTestValue() {
                  return testValue.get();
              }
       
              public void setTestValue(String value) {
                  testValue.set(value);
              }
       
              public StringProperty testValueProperty() {
                  return testValue;
              }
          }
       
          @Override
          public void start(Stage primaryStage) {
              ObservableList<TestDataClass> list = FXCollections.observableArrayList();
              for (int i = 0; i < 4; i++) {
                  list.add(new TestDataClass("val " + rows++));
              }
              TableView table = new TableView(list);
       
              TableColumn<TestDataClass, String> tableColumn = new TableColumn<>();
              tableColumn.setCellValueFactory(new PropertyValueFactory<>("testValue"));
              tableColumn.setText("col " + cols++);
              table.getColumns().add(tableColumn);
       
              Button rAdd = new Button("add");
              rAdd.setOnAction((evt) -> {
                  list.add(new TestDataClass("val " + rows++));
              });
       
              Button rDel = new Button("remove");
              rDel.setOnAction((evt) -> {
                  if (!list.isEmpty()) {
                      rows--;
                      int size = list.size();
                      list.remove(size - 1);
                  }
              });
       
              Button cAdd = new Button("add");
              cAdd.setOnAction((evt) -> {
                  TableColumn<TestDataClass, String> col = new TableColumn<>();
                  col.setCellValueFactory(new PropertyValueFactory<>("testValue"));
                  col.setText("col " + cols++);
                  table.getColumns().add(col);
              });
       
              Button cDel = new Button("remove");
              cDel.setOnAction((evt) -> {
                  ObservableList columns = table.getColumns();
                  if (!columns.isEmpty()) {
                      cols--;
                      int size = columns.size();
                      columns.remove(size - 1);
                  }
              });
             
              GridPane grid = new GridPane();
              grid.setVgap(3);
              grid.setHgap(3);
              grid.addRow(0, new Label("row:"), rAdd, rDel);
              grid.addRow(1, new Label("col:"), cAdd, cDel);
       
              VBox root = new VBox(table, grid);
              Scene scene = new Scene(root, 300, 250);
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }
       
          public static void main(String[] args) {
              launch(args);
          }
       
      }


      Steps to reproduce:
      1) remove all rows
      2) add a column
      3) try to add some rows
      Column created on step 2 wont show its content, until you resize it manually.

      Example with screenshots:
      actions:
       remove all rows
       add a column
       add a row
       add a column
       remove row
       add a column
       add some rows

      result:
      http://i.imgur.com/3U6YuxB.png

      after resizing bugged rows:
      http://i.imgur.com/Rvl2WR1.png

      works fine with 8u5 but bugged for me with 8u20

      Attachments

        Activity

          People

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: