title: How to correctly update AbstractTableModel with fireTableDataChanged()?
body: <p>I'm <a href="https://stackoverflow.com/questions/7876090/arrayindexoutofboundsexception-1-on-jtable-creation-tablechanged">still</a> struggling with a <code>JTable</code> that should be automatically updated.</p>
  
  <p>The situation is as follows:
  I instantiate <code>MyTable</code> (extends <code>JTable</code>), and set it in my UI class (<code>MyView</code>). The <code>MyTable</code> class takes the UI class and an instance of the class that contains logic as parameters):</p>
  
  <pre><code>...
  private JPanel createTablePanel() {
      tablePanel = new JPanel();
      myTable = new MyTable(this,mymeth);
      setMyTable(myTable);
      JScrollPane scrollPane = new JScrollPane(getMyTable());
      tablePanel.add(scrollPane);
      return tablePanel;
  }
  </code></pre>
  
  <p><code>MyTable</code> itself looks like below. An extension of <code>AbstractTableModel</code> (<code>MyTableModel</code>) is set to it. An extension of <code>TableModelListener</code> is set to the model. And finally an extension of <code>ListSelectionListener</code> is set to the model's <code>SelectionModel</code>.</p>
  
  <pre><code>public class MyTable extends JTable implements TableModelListener
  {
  
  public MyTable(MyView myView, MyMethods mymeth)
  {
  
      AbstractTableModel tableModel = new MyTableModel(mymeth);
      setModel(tableModel);
      getModel().addTableModelListener(new MyTableModelListener());
      setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      setCellSelectionEnabled(true);
      getColumnModel().getSelectionModel().addListSelectionListener(new MyTableSelectionListener(this, mymeth, myView));
      setPreferredScrollableViewportSize(this.getPreferredSize());
  
  }
  
  }
  </code></pre>
  
  <p>Let's have a quick look at the model's constructor.</p>
  
  <pre><code>public MyTableModel(MyMethods mymeth) {
      dataObject = new MyData(mymeth);
      myData = dataObject.getMyData();
      colTitles = dataObject.getColTitles();
  }
  </code></pre>
  
  <p><code>MyData</code> compiles the data for the table: A <code>Vector&lt;Vector&lt;Object&gt;&gt;</code>, that consists of three <code>Vector&lt;Object&gt;</code>s (the table data) and a <code>String[]</code> (The column titles). The data itself comes from a graph via <code>mymeth</code>, the logic class' instance.</p>
  
  <p>Whenever a table <em>column</em> is clicked, a popup (i.e. <code>JOptionPane</code>) object is instantiated, which presents a selection of values for the 3rd row in the selected column. The user chooses a value and the value is set to the <em>data model</em>. <strong>Note</strong> the way the table is updated after that.</p>
  
  <pre><code>public MyOptionPane(int i, MyMethods mymeth, MyView myView) {
      this.view = myView;
      String sourceString = mymeth.getSourceString(i); // Gets a String from a
  String[]. In this Array, the order is the same as in the table.
      String tag = null;
      tag = (String) JOptionPane.showInputDialog(this, "Choose a tag for \"" + sourceString + "\"", "String tagging" , JOptionPane.PLAIN_MESSAGE, null, myView.getTags().toArray(), myView.getTags().get(0));
      mymeth.setTag(i, tag);
  
      // This is where fireTableDataChanged() didn't work, but this did
              MyTableModel model = new MyTableModel(mymeth); // New model instance
      view.getMyTable().setModel(model); // reset new model to table
  }
  </code></pre>
  
  <p>This works. However, from what I've read I shold be able to simply call <code>fireTableDataChanged()</code> on the model and the table should update itself. However, this doesn't work. User kleopatra has <a href="https://stackoverflow.com/questions/7876090/comments#comment-9647775">commented</a> to an answer in a previous post: </p>
  
  <blockquote>
    <p>do not call any of the model's fireXX methods from any code external to the model.
    Instead implement the model to do so when anything changed</p>
  </blockquote>
  
  <p>So: <strong>Can I call <code>fireTableDataChanged()</code> within such a structure at all?</strong> And if so, where and how?</p>
  
  <p>Thanks in advance for all pieces of enlightenment!</p>