title: Deleting row from JTable after valueChanged event is triggered
body: <p>I'm using ListSelectionListener to update my <code>JTextField</code> (countryTxt) from selected row.</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.JTextField;
  import javax.swing.SwingUtilities;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  import javax.swing.table.DefaultTableModel;
  
  public class App {
  
      JFrame frame = new JFrame();
      JTable table = new JTable();
      DefaultTableModel model = new DefaultTableModel(new Object[][] {},
              new String[] { "Country", "City", "Street" });
      JButton button = new JButton("Remove");
      JTextField countryTxt = new JTextField();
  
      int row;
  
      public App() {
          table.setModel(model);
          data();
          table.getSelectionModel().addListSelectionListener(
                  new ListSelectionListener() {
                      @Override
                      public void valueChanged(ListSelectionEvent e) {
                          if (!e.getValueIsAdjusting()) {
                              row = table.getSelectedRow();
                              countryTxt.setText((String) model
                                      .getValueAt(row, 0));
                          }
                      }
                  });
          button.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent arg0) {
                  model.removeRow(row);
              }
          });
          frame.add(countryTxt,BorderLayout.NORTH);
          frame.add(new JScrollPane(table), BorderLayout.CENTER);
          frame.add(button, BorderLayout.SOUTH);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setVisible(true);
          frame.setLocationRelativeTo(null);
      }
  
      public void data() {
          model.addRow(new String[] { "USA", "New York", "First street" });
          model.addRow(new String[] { "Russia", "Moscow", "Second street" });
          model.addRow(new String[] { "Japan", "Osaka", "Osaka street" });
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  new App();
              }
          });
      }
  }
  </code></pre>
  
  <p>But when I select a row and click a <code>button</code> it trows me and <code>ArrayIndexOutOfBounds</code> exception. When I don't select a row in my table and click a <code>button</code> everything works fine. Obviously I can delete a row when <code>valueChanged</code> event is not triggered. So my question is: How to delete a row after <code>valueChanged</code> event is triggered. Thanks in advance.</p>