title: Resize JavaFX table
body: <p>I have this simple example of a table.</p>
  
  <pre><code>   import javafx.application.Application;
  import javafx.beans.property.SimpleStringProperty;
  import javafx.beans.value.ChangeListener;
  import javafx.beans.value.ObservableValue;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.EventHandler;
  import javafx.geometry.Insets;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.control.Label;
  import javafx.scene.control.TableCell;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableColumn.CellEditEvent;
  import javafx.scene.control.TableView;
  import javafx.scene.control.TextField;
  import javafx.scene.control.cell.PropertyValueFactory;
  import javafx.scene.layout.Priority;
  import javafx.scene.layout.VBox;
  import javafx.scene.text.Font;
  import javafx.stage.Stage;
  import javafx.util.Callback;
  
  
  public class MainApp extends Application
  {
  
      private TableView&lt;Person&gt; table = new TableView&lt;&gt;();
      private final ObservableList&lt;Person&gt; data
          = FXCollections.observableArrayList(
              new Person("Processor", "72"),
              new Person("RAM", "78"),
              new Person("HDD Free Space", "890"),
              new Person("Lan Adapter NIC 1", "36"),
              new Person("Lan Adapter NIC 2", "67"));
  
      public static void main(String[] args)
      {
          launch(args);
      }
  
      @Override
      public void start(Stage stage)
      {
          Scene scene = new Scene(new Group());
          stage.setTitle("Table View Sample");
          //stage.setWidth(850);
          //stage.setHeight(550);
  
          final Label label = new Label("Address Book");
          label.setFont(new Font("Arial", 20));
  
          table.setEditable(false);
          Callback&lt;TableColumn, TableCell&gt; cellFactory
              = new Callback&lt;TableColumn, TableCell&gt;()
              {
                  @Override
                  public TableCell call(TableColumn p)
                  {
                      return new EditingCell();
                  }
              };
  
          table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
  
          TableColumn firstNameCol = new TableColumn("Credentials");
          //firstNameCol.setPrefWidth(300);
          firstNameCol.setMinWidth(50);
          //firstNameCol.prefWidthProperty().bind(table.widthProperty().divide(2)); // w * 1/2
  
          firstNameCol.setCellValueFactory(new PropertyValueFactory&lt;Person, String&gt;("firstName"));
          firstNameCol.setCellFactory(cellFactory);
          firstNameCol.setOnEditCommit(
              new EventHandler&lt;CellEditEvent&lt;Person, String&gt;&gt;()
              {
                  @Override
                  public void handle(CellEditEvent&lt;Person, String&gt; t)
                  {
                      ((Person) t.getTableView().getItems().get(
                          t.getTablePosition().getRow())).setFirstName(t.getNewValue());
                  }
              }
          );
  
          TableColumn lastNameCol = new TableColumn("Value");
          //lastNameCol.setPrefWidth(300);
          lastNameCol.setMinWidth(50);
          //lastNameCol.prefWidthProperty().bind(table.widthProperty().divide(2));  // w * 1/2
  
          lastNameCol.setCellValueFactory(new PropertyValueFactory&lt;Person, String&gt;("lastName"));
          lastNameCol.setCellFactory(cellFactory);
          lastNameCol.setOnEditCommit(
              new EventHandler&lt;CellEditEvent&lt;Person, String&gt;&gt;()
              {
                  @Override
                  public void handle(CellEditEvent&lt;Person, String&gt; t)
                  {
                      ((Person) t.getTableView().getItems().get(
                          t.getTablePosition().getRow())).setLastName(t.getNewValue());
                  }
              }
          );
  
          table.setItems(data);
          table.getColumns().addAll(firstNameCol, lastNameCol);
  
          final VBox vbox = new VBox();
          VBox.setVgrow(table, Priority.ALWAYS);
          vbox.setSpacing(5);
          vbox.setPadding(new Insets(10, 0, 0, 10));
          vbox.getChildren().addAll(label, table);
  
          ((Group) scene.getRoot()).getChildren().addAll(vbox);
  
          stage.setScene(scene);
          stage.show();
      }
  
      public static class Person
      {
  
          private final SimpleStringProperty firstName;
          private final SimpleStringProperty lastName;
  
          private Person(String fName, String lName)
          {
              this.firstName = new SimpleStringProperty(fName);
              this.lastName = new SimpleStringProperty(lName);
          }
  
          public String getFirstName()
          {
              return firstName.get();
          }
  
          public void setFirstName(String fName)
          {
              firstName.set(fName);
          }
  
          public String getLastName()
          {
              return lastName.get();
          }
  
          public void setLastName(String fName)
          {
              lastName.set(fName);
          }
  
      }
  
      class EditingCell extends TableCell&lt;Person, String&gt;
      {
  
          private TextField textField;
  
          public EditingCell()
          {
          }
  
          @Override
          public void startEdit()
          {
              if (!isEmpty())
              {
                  super.startEdit();
                  createTextField();
                  setText(null);
                  setGraphic(textField);
                  textField.selectAll();
              }
          }
  
          @Override
          public void cancelEdit()
          {
              super.cancelEdit();
  
              setText((String) getItem());
              setGraphic(null);
          }
  
          @Override
          public void updateItem(String item, boolean empty)
          {
              super.updateItem(item, empty);
  
              if (empty)
              {
                  setText(null);
                  setGraphic(null);
              }
              else
              {
                  if (isEditing())
                  {
                      if (textField != null)
                      {
                          textField.setText(getString());
                      }
                      setText(null);
                      setGraphic(textField);
                  }
                  else
                  {
                      setText(getString());
                      setGraphic(null);
                  }
              }
          }
  
          private void createTextField()
          {
              textField = new TextField(getString());
              textField.setMinWidth(this.getWidth() - this.getGraphicTextGap() * 2);
              textField.focusedProperty().addListener(new ChangeListener&lt;Boolean&gt;()
              {
                  @Override
                  public void changed(ObservableValue&lt;? extends Boolean&gt; arg0,
                      Boolean arg1, Boolean arg2)
                  {
                      if (!arg2)
                      {
                          commitEdit(textField.getText());
                      }
                  }
              });
          }
  
          private String getString()
          {
              return getItem() == null ? "" : getItem().toString();
          }
      }
  }
  </code></pre>
  
  <p>I want resize the table and fit the main stage when I resize the window. How I can do this?</p>
  
  <p>P.S I tested to add <code>table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);</code> but nothing is changed.</p>