title: Add row to JTable with AbstractTableModel
body: <p>I need help at adding a empty row to my JTable. I use a AbstractTableModel for my JTable! I have here a small executable program for you so it is easier to help me.</p>
  
  <p>Main Class - TestClass.java</p>
  
  <pre><code>package testproject;
  
  import java.awt.event.ActionEvent;
  import java.util.ArrayList;
  
  import javax.swing.AbstractAction;
  import javax.swing.Action;
  import javax.swing.JFrame;
  import javax.swing.JMenu;
  import javax.swing.JMenuBar;
  import javax.swing.JTable;
  
  public class TestClass {
  
      String[] header = {"Name", "Quantity"};
      ArrayList&lt;Object[]&gt; data = new ArrayList&lt;Object[]&gt;();
  
      public TestClass() {
          data.add(new Object[]{"Apple", "234"});
          data.add(new Object[]{"Banana", "123"});
          data.add(new Object[]{"Cranberry", "346"});
  
          JFrame frame = new JFrame();
          JTable table = new JTable(new Model(data, header));
          JMenuBar menubar = new JMenuBar();
          JMenu editmenu = new JMenu("Edit");
  
          Action addrowaction = new AbstractAction("Add Row") {
              private static final long serialVersionUID = 1433684360133156145L;
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  data.add(new Object[9]);
              }
          };
  
          frame.add(table);
  
          frame.setJMenuBar(menubar);
          menubar.add(editmenu);
          editmenu.add(addrowaction);
  
          frame.setLocationByPlatform(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
          frame.pack();
      }
  
      public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  new TestClass();
              }
          });
      }
  }
  </code></pre>
  
  <p>Table Model - Model.java</p>
  
  <pre><code>package testproject;
  
  import java.util.ArrayList;
  
  import javax.swing.table.AbstractTableModel;
  
  public class Model extends AbstractTableModel{
      private static final long serialVersionUID = 6889542282067432083L;
  
      private String[] header;
      private ArrayList&lt;Object[]&gt; data;
  
      public Model(ArrayList&lt;Object[]&gt; data, String[] header) {
          this.header = header;
          this.data = data;
      }
  
      @Override
      public int getColumnCount() {
          return header.length;
      }
  
      @Override
      public String getColumnName(int column) {
          return header[column];
      }
  
      @Override
      public int getRowCount() {
          return data.size();
      }
  
      @Override
      public Object getValueAt(int row, int column) {
          return data.get(row)[column];
      }
  
      @Override
      public void setValueAt(Object value, int row, int column) {
          data.get(row)[column] = value;
          fireTableCellUpdated(row, column);
      }
  }
  </code></pre>
  
  <p>Basically I want to use a Action in the edit menu to add a empty row. Please do not answer with other links! I searched for it but don't understand it or it isnt suitable for my program!</p>
  
  <p>EDIT:
  Updated the source as suggested by <a href="https://stackoverflow.com/users/992484/madprogrammer">MadProgrammer</a>! There is only one problem left. How I update the JTable so the new Row is displayed at the moment I have to resize the Window and the Table is updating!</p>
  
  <ul>
  <li>Thank you for help</li>
  </ul>