title: JTable: Detect cell data change
body: <p><strong>In Netbeans, I used the GUI Builder to insert a JTable into my application.</strong></p>
  
  <p>I have just one class (CustomerDB) so far which is:</p>
  
  <pre><code>package CustomerDB;
  
  import [...];
  
  public class CustomerDB extends javax.swing.JFrame {
  
      CellEditorListener ChangeNotification = new CellEditorListener() {
          public void editingCanceled(ChangeEvent e) {
              System.out.println("The user canceled editing.");
          }
  
          public void editingStopped(ChangeEvent e) {
              System.out.println("The user stopped editing successfully.");
          }
      };
  
      public CustomerDB() {
          customerTable = new javax.swing.JTable();
          customerTable.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null}
              },
              new String [] {
                  "ID", "Name", "Address", "Phone"
              }
          ) {
              Class[] types = new Class [] {
                  java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
              };
  
              public Class getColumnClass(int columnIndex) {
                  return types [columnIndex];
              }
          });
          customerTable.getDefaultEditor(String.class).addCellEditorListener(ChangeNotification);
      } 
  
      public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new CustomerDB().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify
      [...]
      private javax.swing.JTable customerTable;
      [...]
      // End of variables declaration
  
  }
  </code></pre>
  
  <p><strong>Whenever a user changes data in the table, I want to get the old value (optional) and the new value of that cell.</strong></p>
  
  <p>In order to get this data, I tried to implement an event listener:</p>
  
  <pre><code>    CellEditorListener ChangeNotification = new CellEditorListener() {
          public void editingCanceled(ChangeEvent e) {
              System.out.println("The user canceled editing.");
          }
  
          public void editingStopped(ChangeEvent e) {
              System.out.println("The user stopped editing successfully.");
          }
      };
  </code></pre>
  
  <p><strong>Then I assign this CellEditorListener to the table (its cell editor):</strong></p>
  
  <pre><code>    customerTable.getDefaultEditor(String.class).addCellEditorListener(ChangeNotification);
  </code></pre>
  
  <p><strong>This works so far. But it doesn't yet enable me to detect the old and the new value of this cell. What else do I have to do?</strong></p>
  
  <p>Thank you very much in advance!</p>