title: How to add dynamic columns and rows to TableView in java fxml
body: <p>In java fxml I am retrieving the data from .csv file. I am adding dynamic columns and rows to table view and columns are adding to it but not the rows.
  I am trying and searching internet but I could not get any suitable result.</p>
  
  <p>My code:-</p>
  
  <pre><code>public class FXMLDocumentController {
  
      @FXML
      private TableView tableView;
      String headers[] = null;
      String items[] = null;
  
      Employee ee;
  
      @FXML
      private void initialize() {
          Insert();
      }
  
      public void Insert() {
          List&lt;String&gt; columns = new ArrayList&lt;String&gt;();
          List&lt;String&gt; rows = new ArrayList&lt;String&gt;();
          ObservableList&lt;ObservableList&gt; csvData = FXCollections.observableArrayList();
  
          try {
              int columnIndex = 0;
              TableColumn[] tableColumns;
              File f = new File("C:\\Users\\admin\\Desktop\\Project\\shipforecast\\Data\\Recieve\\ShipId-1432530905282-1.csv");
              if (f.exists() &amp;&amp; !f.isDirectory()) {
                  FileReader fin = new FileReader(f);
                  BufferedReader in = new BufferedReader(fin);
                  String l;
                  int i = 0;
  
                  while ((l = in.readLine()) != null) {
  
                      if (i &lt; 1) {
                          headers = l.split(",");
  
                          for (String w : headers) {
                              columns.add(w);
  
                          }
  
                          tableColumns = new TableColumn[columns.size()];
                          columnIndex = 0;
                          for (String columName : columns) {
  
                              //System.out.println("dynamic.FXMLDocumentController.Insert()"+columns.size());
                              tableColumns[columnIndex++] = new TableColumn(columName);
                          }
  
                          tableView.getColumns().addAll(tableColumns);
                      } else {
                          ObservableList&lt;String&gt; row = FXCollections.observableArrayList();
                          items = l.split(",");
                          for (String item:items) {
  
                              row.add(item);
                          }
                          csvData.add(row);
                          System.out.println("hi");
  
                      }
                      i++;
                      tableView.getItems().add(csvData);
                  }
              } else {
                  System.out.println("File Not Found");
              }
          } catch (Exception e) {
              System.out.println(e);
          }
  
      }
  }
  </code></pre>