title: TableView automatic row height resizing - JavaFX
body: <p>If I have a <code>TableView</code> containing a <code>TableColumn</code> like so:</p>
  
  <pre><code>private TableColumn&lt;Foo, ObservableList&lt;Foo2&gt;&gt; col;
  </code></pre>
  
  <p>I can have it nicely display a list for me. When the size of that list increases, however, the size of the cell (and row) stays constant, and so some of my cell gets cut off. If I resize the column manually, the table will correctly alter the height of the row and it will look as it should. </p>
  
  <p>Do I need to bind the height of the row/cell to the size of the <code>ObservableList</code> somehow, or is there a better way to have the table automatically adjust itself without user intervention?</p>
  
  <p>Contained example:</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.control.ContentDisplay;
  import javafx.scene.control.Label;
  import javafx.scene.control.TableCell;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableView;
  import javafx.scene.control.cell.PropertyValueFactory;
  import javafx.scene.layout.GridPane;
  import javafx.stage.Stage;
  import javafx.util.Callback;
  
  public class CellResizing extends Application {
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
  
          GridPane root = new GridPane();
          ObservableList&lt;MyFoo&gt; list = FXCollections.observableArrayList();
          list.add(new MyFoo());
          list.get(0).foosProperty().get().add(new Foo2("First Item"));
  
          TableView&lt;MyFoo&gt; table = new TableView&lt;MyFoo&gt;();
          TableColumn&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt; col = new TableColumn&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;("List");
          col.setCellValueFactory(new PropertyValueFactory&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;("foos"));
          Callback&lt;TableColumn&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;, TableCell&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;&gt; toolTipFactory =
                  new Callback&lt;TableColumn&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;, TableCell&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;&gt;() {
              @Override
              public TableCell&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt; call(final TableColumn&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt; param) {
                  final TableCell&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt; cell = new TableCell&lt;MyFoo, ObservableList&lt;Foo2&gt;&gt;() {
                      @Override
                      public void updateItem(ObservableList&lt;Foo2&gt; item, boolean empty) {
                          super.updateItem(item, empty);
                          if (empty || item == null) {
                              setText(null);
                              setTooltip(null);
                          } else {
                              GridPane grid = new GridPane();
                              int modulus;
                              if (item.size() &lt; 4) {
                                  modulus = 1;
                              }
                              else if (item.size() &lt; 9) {
                                  modulus = 2;
                              }
                              else {
                                  modulus = 3;
                              }
                              for (int i = 0; i &lt; item.size(); ++i) {
                                  Label label = new Label();
                                  label.setText(item.get(i).toString());
                                  grid.add(label, i % modulus, (i % item.size()) / modulus);
                              }
                              setGraphic(grid);
                              setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
                          }
                      }
                  };
                  return cell;
              }
          };
          col.setCellFactory(toolTipFactory);
          table.getColumns().add(col);
  
          Button button = new Button("Add to list");      
          button.setOnAction(new EventHandler&lt;ActionEvent&gt;() {            
              @Override
              public void handle(ActionEvent event) {
                  list.get(0).foosProperty().get().add(new Foo2("Text"));
              }
          });
          table.setItems(list);
  
          root.add(button, 0, 0);
          root.add(table, 0, 1);
          primaryStage.setScene(new Scene(root, 300, 250));
          primaryStage.show();
      }
  }
  </code></pre>
  
  <p>and the classes MyFoo + Foo2:</p>
  
  <pre><code>import javafx.beans.property.ListProperty;
  import javafx.beans.property.SimpleListProperty;
  import javafx.beans.property.SimpleStringProperty;
  import javafx.beans.property.StringProperty;
  import javafx.collections.FXCollections;
  
  public class MyFoo {
      private ListProperty&lt;Foo2&gt; foos;
  
      public MyFoo() {
          foos = new SimpleListProperty&lt;Foo2&gt;(FXCollections.observableArrayList());
      }
  
      public ListProperty&lt;Foo2&gt; foosProperty() {
          return foos;
      }
  }
  
  class Foo2 {
      private StringProperty text;
  
      public Foo2(String string) {
          text = new SimpleStringProperty(string);
      }
  
      public StringProperty textProperty() {
          return text;
      }
  
      @Override
      public String toString() {
          return text.get();
      }
  
  }
  </code></pre>