title: Update a JTable data completely each time I perform a function
body: <p>Can you help me to make this piece of code workable? I have created a table which change its data each time a function is triggered. The code is composed of three classes.</p>
  
  <p>Table Model</p>
  
  <pre><code>public class MyTableModel extends AbstractTableModel {
  
  
  private static final long serialVersionUID = 1L;
  
  private static String[] header = {"A", "B","C", "so on"};
  
  
  public MyTableModel(){
  
  }
  
  RecordingList data = new RecordingList();
  
  public void addData(RecordingList dataIn) {
      data=dataIn;
      this.fireTableDataChanged();
  
      }
  
  @Override
  public int getColumnCount() {
      return header.length; //length;
  }
  
  @Override
  public int getRowCount() {
      return data.size();
  
  }
  
  @Override
  public String getColumnName(int col) {
      return header[col];
  }
  
  @Override
  public String getValueAt(int row, int col)
  {
      Object[] rowSelected = data.getRecordingRow(row);
  
      return rowSelected[col].toString();
  
  }
  
  }
  </code></pre>
  
  <p>JTable</p>
  
  <pre><code> public class DynamicTable extends JTable implements TableModelListener{
  
  /**
   * 
   */
  MyTableModel model;
  
  private static final long serialVersionUID = 1L;
  
  public DynamicTable() {
  
      model = new MyTableModel();
      initialize();
  
  }
  
  void initialize(){
  
  
          setFillsViewportHeight(true);
          setModel(model);
          getModel().addTableModelListener(this);
          setForeground(Color.BLACK);
          setShowGrid(true);
          setShowVerticalLines(true);
          setBackground(Color.WHITE);
  
          try {
              // 1.6+
              setAutoCreateRowSorter(true);
          } catch(Exception continuewithNoSort) {
      }
  }
  public void tableChanged(TableModelEvent e) {
  
      TableModel newModel = (TableModel)e.getSource();
      model=(MyTableModel)newModel;
      setModel(model);
  
      // Do something with the data...
  }
  }
  </code></pre>
  
  <p>Finally I have implemented a Third class which needs to update the table and the model</p>
  
  <p>This is obviously a really WRONG approach and I put it here to give you an understanding of what I am trying to achieve:</p>
  
  <pre><code>   RecordingList recordingList = cr.getResultQuery();
  
              MyTableModel newModel = new MyTableModel();
              newModel.addData(recordingList);
  
              TableModelEvent event= new TableModelEvent(newModel);
  
              DynamicTable dt =new DynamicTable() ;
              dt.tableChanged(event);
  </code></pre>