title: java : sort and delete or refresh data make exception in jtable
body: <p>please excute this code with java, and then..</p>
  
  <p><code>button pattern1 -&gt; button pattern2 -&gt; table sort with any columns. -&gt; 
  button delete -&gt; exception.</code></p>
  
  <p>Why exception occured?</p>
  
  <p>here's code.</p>
  
  <p>please help me..</p>
  
  <h1>===============================================</h1>
  
  <pre><code>public class Test extends JFrame {
  
      private DefaultTableModel modelTest = new DefaultTableModel();
      private JTable tableTest = new JTable(modelTest);
      private JScrollPane paneTest = new JScrollPane(tableTest);
  
      private JButton button1 = new JButton("pattern1");
      private JButton button2 = new JButton("pattern2");
      private JButton button3 = new JButton("delete");
  
      private void compInit() {
          paneTest.setBounds(0, 0, 778, 300);
          button1.setBounds(250, 320, 80, 20);
          button2.setBounds(450, 320, 80, 20);
          button3.setBounds(300, 400, 80, 20);
  
          DefaultTableModel tmp = modelTest;
  
          tmp.addColumn("  ");
          tmp.addColumn("col1");
          tmp.addColumn("col2");
          tmp.addColumn("col3");
          tmp.addColumn("col4");
          tmp.addColumn("col5");
          tmp.addColumn("col6");
          tmp.addColumn("col7");
  
          try {
              tableTest.setDefaultRenderer(Class.forName("java.lang.String"), new DefaultTableCellRenderer());
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
          tableTest.setAutoCreateRowSorter(true);
          tableTest.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          tableTest.getColumnModel().getColumn(0).setPreferredWidth(20);
          tableTest.getColumnModel().getColumn(1).setPreferredWidth(45);
          tableTest.getColumnModel().getColumn(2).setPreferredWidth(110);
          tableTest.getColumnModel().getColumn(3).setPreferredWidth(60);
          tableTest.getColumnModel().getColumn(4).setPreferredWidth(100);
          tableTest.getColumnModel().getColumn(5).setPreferredWidth(227);
          tableTest.getColumnModel().getColumn(6).setPreferredWidth(100);
          tableTest.getColumnModel().getColumn(7).setPreferredWidth(100);
          tableTest.getTableHeader().setForeground(new Color(105, 105, 105));
  
          this.add(button1);
          this.add(button2);
          this.add(button3);
          this.add(paneTest);
      }
  
      private void pattern1() {
          for (int i = 0; i &lt; 10; i++) {
              Vector rowData = new Vector&lt;&gt;();
              rowData.add(false);
              rowData.add(i + 1);
              rowData.add("a : " + i);
              rowData.add("b : " + i);
              rowData.add("c : " + i);
              rowData.add("d : " + i);
              rowData.add("e : " + i);
              rowData.add("f : " + i);
              modelTest.addRow(rowData);
          }
      }
  
      private void pattern2() {
          for (int i = 0; i &lt; 10; i++) {
              Vector rowData = new Vector&lt;&gt;();
              rowData.add(false);
              rowData.add(i + 1);
              rowData.add("z : " + i);
              rowData.add("y : " + i);
              rowData.add("x : " + i);
              rowData.add("w : " + i);
              rowData.add("v : " + i);
              rowData.add("u : " + i);
              modelTest.addRow(rowData);
          }
      }
  
      private void delete() {
          DefaultTableModel tmp = modelTest;
          tmp.getDataVector().removeAllElements();
          tableTest.repaint();
      }
  
  
      private void eventInit() {
          button1.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  pattern1();
              }
          });
          button2.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  pattern2();
              }
          });
          button3.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  delete();
              }
          });
      }
  
      public Test() {
          this.setLayout(null);
          this.compInit();
          this.eventInit();
          this.setSize(778, 500);
          this.setLocationRelativeTo(null);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.setVisible(true);
      }
  
      public static void main(String[] ar) {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  new Test();
              }
          });
      }
  
  }
  </code></pre>