title: Remove columns from table view javafx
body: <p>I have a table view in javafx and I add dynamically the columns because I don't know the number of the columns. I want when I click in a button all the rows and columns of the tableView to be removed. I have the code below. I want before I add new data in the table to remove all the columns from it. I tried a lot of things that I found online but nothing worked. Thanks.</p>
  
  <pre><code>public void handleEventsClick(){
      String tableName = (String) events.getSelectionModel().getSelectedItem();
  
      ObservableList&lt;ObservableList&gt; transitionEvents = FXCollections.observableArrayList();
  
      tableColumns = new TableColumn[traEv.size()];
  
      int trEvSize = 0;
  
      for(int i = 0; i &lt; traEv.size();i++){
          ArrayList&lt;TransitionSubsequencePair&gt; tep = traEv.get(i); 
  
          TableColumn tc = new TableColumn("TrEv:" + i);
          tableColumns[i] = tc;
              final int j = i;
              tc.setCellValueFactory(new Callback&lt;CellDataFeatures&lt;ObservableList,String&gt;,ObservableValue&lt;String&gt;&gt;(){                    
                  public ObservableValue&lt;String&gt; call(CellDataFeatures&lt;ObservableList, String&gt; param) {                                                                                              
                      return new SimpleStringProperty(param.getValue().get(j).toString());                        
                  }                    
              });
              eventsTableView.getColumns().addAll(tc);
      }
  
      ObservableList&lt;String&gt; row = FXCollections.observableArrayList();
      row.clear();
      for(int i = 0; i &lt; traEv.size();i++){
          ArrayList&lt;TransitionSubsequencePair&gt; tep = traEv.get(i); 
  
          ArrayList&lt;String&gt; seenTables = new ArrayList&lt;String&gt;();
          for(TransitionSubsequencePair tre: tep){
              System.out.println(tre.getTable());
              String lala = "";
              if(tre.getTable().equals(tableName) &amp;&amp; (!seenTables.contains(tre.getTable()) || seenTables.isEmpty())){
                  System.out.println(i);
                  lala += tre.getTransition() + ":" + tre.getSubsequence() + ",";
                  row.add(lala);
                  seenTables.add(tre.getTable());
              }
              System.out.println("--"+lala);
          }
  
  
      }
      transitionEvents.add(row);
  
  
      eventsTableView.setItems(transitionEvents); // finally add data to tableview
  
  
  }
  </code></pre>