title: How to add button in JavaFX table view
body: <p>I have searched at Google and Stackoverflow for this and I just don't get the given examples. Can someone please explain it to me. </p>
  
  <p>I want to add a button to the last column of a table view and when it gets clicked it should trigger a listener and pass the object of the buttons row. I just do not get the following example from <em><a href="https://gist.github.com/jewelsea/3081826">gist.github.com</a></em>:</p>
  
  <p>This is my full current code:</p>
  
  <pre><code>public class SchermdeelWerkplaats extends BorderPane{
  
      //ATD moeder klasse met alle collecties etc.
      private ATD $;
  
      TableView tabel = new TableView();
      Button nieuwTaak = new Button("Nieuwe taak inboeken");
      final ObservableList&lt;Task&gt; data = FXCollections.observableArrayList();
  
      public SchermdeelWerkplaats(ATD a) {
  
          $ = a;
  
          data.addAll($.agenda);
  
          tabel.setEditable(false);
          tabel.setPlaceholder(new Label("Geen taken"));
  
          TableColumn c1 = new TableColumn("datum");
          c1.setMinWidth(200);
          TableColumn c2 = new TableColumn("type");
          c2.setMinWidth(100);
          TableColumn c3 = new TableColumn("uren");
          c3.setMinWidth(100);
          TableColumn c4 = new TableColumn("klaar");
          c4.setMinWidth(200);
          TableColumn c5 = new TableColumn("Werknemer");
          c5.setMinWidth(100);
          TableColumn c6= new TableColumn("Auto");
          c6.setMinWidth(400);
          TableColumn c7= new TableColumn("Actie");
          c7.setMinWidth(400);
  
          TableColumn col_action = new TableColumn&lt;&gt;("Action");
  
          col_action.setCellValueFactory(
                  new Callback&lt;TableColumn.CellDataFeatures&lt;Task, Boolean&gt;, 
                  ObservableValue&lt;Boolean&gt;&gt;() {
  
              @Override
              public ObservableValue&lt;Boolean&gt; call(TableColumn.CellDataFeatures&lt;Task, Boolean&gt; p) {
                  return new SimpleBooleanProperty(p.getValue() != null);
              }
          });
  
          col_action.setCellFactory(
              new Callback&lt;TableColumn&lt;Task, Task&gt;, TableCell&lt;Task, Task&gt;&gt;() {
  
                  @Override
                  public TableCell&lt;Task, Task&gt; call(TableColumn&lt;Task, Task&gt; p) {
                      return new ButtonCell();
                  }
              }
          );
  
          c1.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Date&gt;("date")
          );
          c2.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Task.TaskType&gt;("type")
          );
          c3.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Double&gt;("hours")
          );
          c4.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Boolean&gt;("done")
          );
          c5.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Employee&gt;("employee")
          );
          c6.setCellValueFactory(
              new PropertyValueFactory&lt;Task,Car&gt;("car")
          );
  
          tabel.getColumns().addAll(c1, c2, c3, c4, c5, c6, c7);
          tabel.setItems(data);
  
          setCenter(tabel);
          setBottom(nieuwTaak);
  
      }
  
      //letterlijk van internet geplukt en datatype aangepast
      private class ButtonCell extends TableCell&lt;Task, Task&gt; {
  
  
          private Button cellButton;
  
          ButtonCell(){
                cellButton = new Button("jjhjhjh");
              cellButton.setOnAction(new EventHandler&lt;ActionEvent&gt;(){
  
                  @Override
                  public void handle(ActionEvent t) {
                      // do something when button clicked
                      Task record = getItem();
                      // do something with record....
                  }
              });
          }
  
          //Display button if the row is not empty
          @Override
          protected void updateItem(Task record, boolean empty) {
              super.updateItem(record, empty);
              if(!empty){
                  cellButton.setText("Something with "+record);
                  setGraphic(cellButton);
              } else {
                  setGraphic(null);
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Now the part where I have to create a <code>ButtonCell extends TableCell</code> is understandable. But how to assign this to the column?</p>
  
  <p>I understand this:</p>
  
  <pre><code>c1.setCellValueFactory(
          new PropertyValueFactory&lt;Task,Date&gt;("date")
      );
  </code></pre>
  
  <p>But not this:</p>
  
  <pre><code>           TableColumn col_action = new TableColumn&lt;&gt;("Action");
  
              col_action.setCellValueFactory(
                      new Callback&lt;TableColumn.CellDataFeatures&lt;Task, Boolean&gt;, 
                      ObservableValue&lt;Boolean&gt;&gt;() {
  
                  @Override
                  public ObservableValue&lt;Boolean&gt; call(TableColumn.CellDataFeatures&lt;Task, Boolean&gt; p) {
                      return new SimpleBooleanProperty(p.getValue() != null);
                  }
              });
  
              col_action.setCellFactory(
                  new Callback&lt;TableColumn&lt;Task, Task&gt;, TableCell&lt;Task, Task&gt;&gt;() {
  
                      @Override
                      public TableCell&lt;Task, Task&gt; call(TableColumn&lt;Task, Task&gt; p) {
                          return new ButtonCell();
                      }
                  }
              );
  </code></pre>