title: Get Checkbox value in a table in JavaFX
body: <p>I have a table and it has a column with checkboxes.</p>
  
  <p><img src="https://i.stack.imgur.com/7DeRe.png" alt="The output so far"></p>
  
  <p>On a button click I want to find out which checkboxes are checked and which are not.
  So far I managed to create checkboxes in a table.
  The code is as follows.</p>
  
  <pre><code>public class TTEs implements Initializable {
  
      @FXML
      private TableView&lt;TestObject&gt; tableReport;
  
      @FXML
      private TableColumn&lt;TestObject, String&gt; name;
  
      @FXML
      private TableColumn&lt;TestObject, Boolean&gt; checkbox;
  
      @FXML
      public void getValues() {        
          //the method will get what check boxes are checked (this part is the problem)
      }
  
      @Override
      public void initialize(URL arg0, ResourceBundle arg1) { 
          ObservableList&lt;TestObject&gt; data = FXCollections.observableArrayList();
          data.add(new TestObject("Test 1", true));
          data.add(new TestObject("Test 2", false));
  
          tableReport.setItems(data);
  
          name.setCellValueFactory(new PropertyValueFactory&lt;TestObject, String&gt;("name"));
          checkbox.setCellValueFactory(new PropertyValueFactory&lt;TestObject, Boolean&gt;("checked"));
  
          checkbox.setCellFactory(new Callback&lt;TableColumn&lt;TestObject, Boolean&gt;,
              TableCell&lt;TestObject, Boolean&gt;&gt;() {
  
              public TableCell&lt;TestObject, Boolean&gt; call(TableColumn&lt;TestObject, Boolean&gt; p) {
                  return new CheckBoxTableCell&lt;TestObject, Boolean&gt;();
              }
          });
      }
  
      //CheckBoxTableCell for creating a CheckBox in a table cell
      public static class CheckBoxTableCell&lt;S, T&gt; extends TableCell&lt;S, T&gt; {
          private final CheckBox checkBox;
          private ObservableValue&lt;T&gt; ov;
  
          public CheckBoxTableCell() {
              this.checkBox = new CheckBox();
              this.checkBox.setAlignment(Pos.CENTER);
  
              setAlignment(Pos.CENTER);
              setGraphic(checkBox);
          } 
  
          @Override public void updateItem(T item, boolean empty) {
              super.updateItem(item, empty);
              if (empty) {
                  setText(null);
                  setGraphic(null);
              } else {
                  setGraphic(checkBox);
                  if (ov instanceof BooleanProperty) {
                      checkBox.selectedProperty().unbindBidirectional((BooleanProperty) ov);
                  }
                  ov = getTableColumn().getCellObservableValue(getIndex());
                  if (ov instanceof BooleanProperty) {
                      checkBox.selectedProperty().bindBidirectional((BooleanProperty) ov);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>When I debug, I find that:</p>
  
  <pre><code>        ov = getTableColumn().getCellObservableValue(getIndex());
          if (ov instanceof BooleanProperty) {
              checkBox.selectedProperty().bindBidirectional((BooleanProperty) ov);
          }
  </code></pre>
  
  <p>In the above condition, it never goes inside the <code>if</code> statement, meaning that the <code>ov</code> is not an instance of <code>BooleanProperty</code>. But when I print the class of <code>ov</code>,</p>
  
  <pre><code>System.out.println(ov.getClass().getName());
  </code></pre>
  
  <p>it prints as </p>
  
  <pre><code>javafx.beans.property.ReadOnlyObjectWrapper
  </code></pre>
  
  <p><code>ReadOnlyObjectWrapper</code> is a subclass of <code>BooleanProperty</code>, so why is the <code>instanceof</code> check not working?</p>