title: Javafx dynamic Table
body: <p>I want create dynamic table with TableView class.</p>
  
  <p>I send to contractor the number of columns (int), columns name (String[]) and rows (Student), but I can't deal with that.
  How I need to define the TableColumn for each one of columns? </p>
  
  <pre><code>public class DynamicTable extends TableView&lt;Student&gt;{
  
  private ObservableList&lt;Student&gt; data;
  private int columnCount;
  private String[] columnName;
  private TableView&lt;Student&gt; tableView;
  
  DynamicTable(){
  
  }
  DynamicTable(int columnCount, Student[] rows, String[] columnName){
  
      this.columnName=columnName;
      this.columnCount=columnCount;
      data = FXCollections.observableArrayList();
      setData(rows);
  }
  
  public void buildTable(){
  
      for(int i=0 ; i&lt;columnCount; i++){
          final int j=i;
          TableColumn&lt;Student,String&gt; col = new TableColumn&lt;Student,String&gt;(columnName[i]); 
  
          //col.setCellValueFactory(new Callback&lt;TableColumn.CellDataFeatures&lt;Student,String&gt;, ObservableValue&lt;String&gt;&gt;() {
  
              //@Override
              //public ObservableValue&lt;String&gt; call(
                  //  CellDataFeatures&lt;Student, String&gt; param) {
  
              //  return new SimpleStringProperty(param.getValue().getAddress());
          //  }
          //});
          tableView.getColumns().addAll(col);
  
          tableView.setItems(data);
      }
  }
  
  public void setData(Student[] rows){
      data.setAll(rows);
  
  }
  public String[] getColumnName(){
      return this.columnName;
  }
  }
  </code></pre>
  
  <p>I be glad for receiving your answer.</p>
  
  <p>Edit: Student class:</p>
  
  <pre><code> public class Student implements  Externalizable
      { 
      private final SimpleIntegerProperty ID;
      private final SimpleStringProperty firstName;
      private final SimpleStringProperty lastName;
      private final SimpleStringProperty address;
      private final SimpleObjectProperty&lt;Date&gt; birthDate;
      private final SimpleStringProperty department;
      private final SimpleIntegerProperty pointsAmount;
      private final SimpleObjectProperty&lt;Date&gt; startStudyingDate;
      private final SimpleIntegerProperty failedAmount;
      private final SimpleDoubleProperty average;
      private final SimpleIntegerProperty lavelByGrade;
      private final SimpleStringProperty pic;
  
      public Student(){
  
          this.ID = new SimpleIntegerProperty();
          this.firstName= new SimpleStringProperty();
          this.lastName= new SimpleStringProperty();
          this.address= new SimpleStringProperty();
          this.birthDate= new SimpleObjectProperty&lt;Date&gt;();
          this.department= new SimpleStringProperty();
          this.pointsAmount= new SimpleIntegerProperty();
          this.startStudyingDate= new  SimpleObjectProperty&lt;Date&gt;();
          this.failedAmount= new SimpleIntegerProperty();
          this.average= new SimpleDoubleProperty();
          this.lavelByGrade= new SimpleIntegerProperty();
          this.pic = new SimpleStringProperty();
      }
  
      public Student(int ID, String firstName, String lastName, String address,
              Date  birthDate, String department,
              int pointsAmount, Date startStudyingDate, int failedAmount, 
              double average, int  lavelByGrade, String pic){
  
          this.ID= new SimpleIntegerProperty(ID);
          this.firstName= new SimpleStringProperty(firstName);
          this.lastName= new SimpleStringProperty(lastName);
          this.address= new SimpleStringProperty(address);
          this.birthDate= new SimpleObjectProperty&lt;Date&gt;(birthDate);
          this.department= new SimpleStringProperty(department);
          this.pointsAmount= new SimpleIntegerProperty(pointsAmount);
          this.startStudyingDate= new  SimpleObjectProperty&lt;Date&gt;(startStudyingDate);
          this.failedAmount= new SimpleIntegerProperty(failedAmount);
          this.average= new SimpleDoubleProperty(average);
          this.lavelByGrade= new SimpleIntegerProperty(lavelByGrade);
          this.pic = new SimpleStringProperty(pic);
      }
  
      public int getID() {
          return ID.get();
      }
      public void setID(int ID) {
          this.ID.set(ID);
      }
  
      public String getFirstName() {
          return firstName.get();
      }
  
      public void setFirstName(String firstName) {
          this.firstName.set(firstName);
      }
  
      public String getLastName() {
          return lastName.get();
      }
  
      public void setLastName(String lastName) {
          this.lastName.set(lastName);
      }
  
      public String getAddress() {
          return address.get();
      }
  
      public void setAddress(String address) {
          this.address.set(address);
      }
  
      public Date getBirthDate() {
          return birthDate.get();
      }
  
      public void setBirthDate(Date birthDate) {
          this.birthDate.set(birthDate);
      }
  
      public String getDepartment() {
          return department.get();
      }
  
      public void setDepartment(String department) {
          this.department.set(department);
      }
  
      public int getPointsAmount() {
          return pointsAmount.get();
      }
  
      public void setPointsAmount(int pointsAmount) {
          this.pointsAmount.set(pointsAmount);
      }
  
      public Date getStartStudyingDate() {
          return startStudyingDate.get();
      }
  
      public void setStartStudyingDate(Date startStudyingDate) {
          this.startStudyingDate.set(startStudyingDate);
      }
  
      public int getFailedAmount() {
          return failedAmount.get();
      }
  
      public void setFailedAmount(int failedAmount) {
          this.failedAmount.set(failedAmount);
      }
  
      public double getAverage() {
          return average.get();
      }
  
      public void setAverage(Double average) {
          this.average.set(average);
      }
  
      public int getLavelByGrade() {
          return lavelByGrade.get();
      }
  
      public void setLavelByGrade(int lavelByGrade) {
          this.lavelByGrade.set(lavelByGrade);
      }
  
      public String getPic() {
          return pic.get();
      }
  
      public void setPic(String pic) {
          this.pic.set(pic);
      }
  
      @Override
      public void readExternal(ObjectInput in) throws IOException,
      ClassNotFoundException {
  
          setID(in.readInt());
          setFirstName((String)in.readObject());
          setLastName((String)in.readObject());
          setAddress((String)in.readObject());
          setBirthDate((Date)in.readObject());
          setDepartment((String)in.readObject());
          setPointsAmount(in.readInt());
          setStartStudyingDate((Date)in.readObject());
          setFailedAmount(in.readInt());
          setAverage(in.readDouble());
          setLavelByGrade(in.readInt());
          setPic((String)in.readObject());
      }
  
      @Override
      public void writeExternal(ObjectOutput out) throws IOException {
  
          out.writeInt(getID());
          out.writeObject(getFirstName()); 
          out.writeObject(getLastName()); 
          out.writeObject(getAddress()); 
          out.writeObject(getBirthDate());
          out.writeObject(getDepartment());
          out.writeInt(getPointsAmount()); 
          out.writeObject(getStartStudyingDate()); 
          out.writeInt(getFailedAmount()); 
          out.writeDouble(getAverage()); 
          out.writeInt(getLavelByGrade());
          out.writeObject(getPic()); 
  
      }
  
  }   
  </code></pre>