title: TableView with different objects (javafx)
body: <p>Im currently developing a application for watching who is responsible for different Patients, however i havent been able to solve how to fill a table with different object types.</p>
  
  <p>Below is my code for my TableView controller. The TableView will end up with four different object typs, all will be retrieved from a database.</p>
  
  <p>I want my table to hold Patient objects, User objects (responsible) and a RelationManager object.  </p>
  
  <p>Below is my code, if you need more of the code, please let me know :-).</p>
  
  <pre><code>package fird.presentation;
  
  
  import fird.Patient;
  import fird.RelationManager;
  import fird.User;
  import fird.data.DAOFactory;
  import fird.data.DataDAO;
  import java.net.URL;
  import java.util.Arrays;
  import java.util.List;
  import java.util.ResourceBundle;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.control.Button;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableView;
  import javafx.scene.control.TextField;
  import javafx.scene.control.cell.PropertyValueFactory;
  
  /**
   * FXML Controller class
   *
   * @author SimonKragh
   */
  public class KMAMainFrameOverviewController implements Initializable {
  
      @FXML
      private TextField txtCPRKMAMainFrame;
      @FXML
      private TableColumn&lt;Patient, String&gt; TableColumnCPR;
      @FXML
      private TableColumn&lt;Patient, String&gt; TableColumnFirstname;
      @FXML
      private TableColumn&lt;Patient, String&gt; TableColumnSurname;
      @FXML
      private TableColumn&lt;User, String&gt; TableColumnResponsible;
      @FXML
      private TableColumn&lt;RelationManager, String&gt; TableColumnLastEdited;
      @FXML
      private TableView&lt;RelationManager&gt; tblPatients;
      @FXML
      private Button btnShowHistory;
      @FXML
      private TableColumn&lt;?, ?&gt; TableColumnDepartment;
  
      /**
       * Initializes the controller clas @FXML private Button btnShowHistory;
       *
       * @FXML private TableColumn&lt;?, ?&gt; TableColumnDepartment; s.
       */
      @Override
      public void initialize(URL url, ResourceBundle rb) {
  
          // Start of logic for the KMAMainFrameOverviewController
          DataDAO dao = DAOFactory.getDataDao();
          TableColumnCPR.setCellValueFactory(new PropertyValueFactory&lt;Patient, String&gt;("CPR"));
          TableColumnFirstname.setCellValueFactory(new PropertyValueFactory&lt;Patient, String&gt;("Firstname"));
          TableColumnSurname.setCellValueFactory(new PropertyValueFactory&lt;Patient, String&gt;("Surname"));
          TableColumnResponsible.setCellValueFactory(new PropertyValueFactory&lt;User, String&gt;("Responsible"));
          TableColumnLastEdited.setCellValueFactory(new PropertyValueFactory&lt;RelationManager, String&gt;("Last Edited"));
          ObservableList&lt;RelationManager&gt; relationData = FXCollections.observableArrayList(dao.getAllActiveRelations());
          tblPatients.setItems(relationData);
          tblPatients.getColumns().addAll(TableColumnCPR, TableColumnFirstname, TableColumnSurname, TableColumnResponsible, TableColumnLastEdited);
          System.out.println(tblPatients.getItems().toString());
      }
  }
  </code></pre>
  
  <p>relationData is a RelationManager object returned. This object contains a User object, a Patient object and a Responsible object.</p>
  
  <p>Best,
  Simon. </p>