title: how to remove all rows in jtable?
body: <p>i have one jtable with listselectionlistener i can dynamically added the new rows in to my table,when i select the row  the selected row content will be appear in text box  i can able to  edit and remove the data ,for my application i stored the  table data into  xml file,when i add new row,that  will be added into table successfully. but when i select a row and update means table doesn't get update(here i call load table()).( but updated values changed in xml file correctly)
  this my sample code for creating table*</p>
  
  <pre><code>    ListSelectionModel selectionModel;
      JTable table1;
      model = new DefaultTableModel();
      table = new JTable(model);       table.setRowHeight(20);
      selectionModel = table.getSelectionModel();                  
      selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  
   selectionModel.addListSelectionListener(new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
  
              stxtBox.setText("");
              ptxtBox.setText("");
              ntxtBox.setText("");
  
              if (!e.getValueIsAdjusting()) {
  
  
  
               model1 = table.getSelectionModel();
                  int lead = model1.getLeadSelectionIndex();
                  int columns = table.getColumnCount();
                  String sip = "";
                  String sport = "";
                  String snoq = "";
                  for (int col = 0; col &lt; columns; col++) {
                      Object o = table.getValueAt(lead, col);
  
                      if (col == 0) {
                          sip += o.toString();
                          stxtBox.setText(sip);
                          selectedip = sip;
  
                      } else if (col == 1) {
  
                          sport += o.toString();
                          ptxtBox.setText(sport);
                          selectedport = sport;
                      } else {
  
                          snoq += o.toString();
                          ntxtBox.setText(snoq);
                      }
                      selectedreq = snoq;
  
                  }
  
  
  
              }table.clearSelection();
          }
      });
  </code></pre>
  
  <p>i load the table content like this</p>
  
  <pre><code>  int rowCount=0;
  
              File file = new File("serverconfig.xml");
  
              if (file.exists())
  
              {
  
                  System.out.print("in load");
                  int e = table.getRowCount();
  
                  if(e&gt; 0)
                  {
  
                  while (table.getRowCount() &gt; 0) {
                      ((DefaultTableModel) table.getModel()).removeRow(0);
                  }
  
                  }
  
  //here i will load table content from my xml file (that's working fine)
  </code></pre>
  
  <p>the problem is when i update my table content i will call loadtable() function ever time i will get this error</p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 1 &gt;= 1
      at java.util.Vector.elementAt(Unknown Source)
      at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
      at javax.swing.JTable.getValueAt(Unknown Source)
      at Testsample$18.valueChanged(Testsample.java:1810)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
      at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
      at javax.swing.DefaultListSelectionModel.insertIndexInterval(Unknown Source)
      at javax.swing.JTable.tableRowsInserted(Unknown Source)
      at javax.swing.JTable.tableChanged(Unknown Source)
      at javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source)
      at javax.swing.table.AbstractTableModel.fireTableRowsInserted(Unknown Source)
      at javax.swing.table.DefaultTableModel.insertRow(Unknown Source)
      at javax.swing.table.DefaultTableModel.addRow(Unknown Source)
      at javax.swing.table.DefaultTableModel.addRow(Unknown Source)
      at Testsample.loadtable(Testsample.java:577)
      at Testsample$10.actionPerformed(Testsample.java:1551)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  </code></pre>