title: Dynamically updating jTable
body: <p>My table will change the entire dataset during runtime.
  My current code looks like below,</p>
  
  <pre><code>public class gui_test_form extends JFrame{
      private JPanel rootpanel;
      private JTable testTable;
      private JScrollPane testScrollPane;
      private JButton testButton;
  
      private String[] columnNames = {"Name", "Color"};
      private Object[][] data = { {"John", "Blue"}, {"Oliver", "Green"}, {"Paul", "Red"} };
  
      public gui_test_form() {
          super("GUI TEST");
          setContentPane(rootpanel);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          pack();
          setVisible(true);
  
          testButton.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent actionEvent) { // Button Clicked
                  //Get new values
                  data[0][0] = "New Value";
                  //Update table
                  testTable.setModel(new DefaultTableModel(data, columnNames));
              }
          });
      }
  }
  </code></pre>
  
  <p>The code works as I expected. But I don't think making a new <code>DefaultTableModel</code> everytime is the best way to go. What should I be doing?</p>
  
  <p>I looked briefly into <code>fireTableChanged()</code> method for <code>AbstractTableModel</code>, but couldn't make it work. I expected it would work since <code>DefaultTableModel</code> is inherited from <code>AbstractTableModel</code>.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>-------Edit-------<br>
  Forgive me if I wasn't clearer before, but the problem is that I want to update the whole dataset. Even the Column names and the number of columns and rows are going to change.<br>
  For example, in the above code I could do this, and it would still work as you'd expect.</p>
  
  <pre><code>//Get new values
  columnNames = new String[]{"Country", "Location", "Latitudes"};
  data = new Object[][]{ {"John", "Blue", "1"}, {"Oliver", "Green", "4"}};
  //Update table
  </code></pre>