title: JTable How to refresh table model after insert delete or update the data.
body: <p>This is my jTable </p>
  
  <pre><code>private JTable getJTable() {
      String[] colName = { "Name", "Email", "Contact No. 1", "Contact No. 2",
              "Group", "" };
      if (jTable == null) {
          jTable = new JTable() {
              public boolean isCellEditable(int nRow, int nCol) {
                  return false;
              }
          };
      }
      DefaultTableModel contactTableModel = (DefaultTableModel) jTable
              .getModel();
      contactTableModel.setColumnIdentifiers(colName);
      jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      return jTable;
  }
  </code></pre>
  
  <p>I will call this method to retrieve the data from database and put it into table model</p>
  
  <pre><code>public void setUpTableData() {
      DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
      ArrayList&lt;Contact&gt; list = new ArrayList&lt;Contact&gt;();
      if (!con.equals(""))
          list = sql.getContactListsByGroup(con);
      else
          list = sql.getContactLists();
      for (int i = 0; i &lt; list.size(); i++) {
          String[] data = new String[7];
  
              data[0] = list.get(i).getName();
              data[1] = list.get(i).getEmail();
              data[2] = list.get(i).getPhone1();
              data[3] = list.get(i).getPhone2();
              data[4] = list.get(i).getGroup();
              data[5] = list.get(i).getId();
  
          tableModel.addRow(data);
      }
      jTable.setModel(tableModel);
  }
  </code></pre>
  
  <p>Currently I was using this method to refresh the table after updating the table data. I will first clear the table </p>
  
  <pre><code>DefaultTableModel tableModel = (DefaultTableModel) jTable.getModel();
  tableModel.setRowCount(0);
  </code></pre>
  
  <p>and then restructure the table model again so it will refresh the jTable. But I was thinking is there any best practices or better way to do that? </p>