Sunday, July 3, 2011

Implementing javax.sql.RowSetListener

The class CoffeesFrame implements only one method from the interface RowSetListener, rowChanged. This method is called when a user adds a row to the table.

  public void rowChanged(RowSetEvent event) {      CachedRowSet currentRowSet = this.myCoffeesTableModel.coffeesRowSet;      try {       currentRowSet.moveToCurrentRow();       myCoffeesTableModel =         new CoffeesTableModel(myCoffeesTableModel.getCoffeesRowSet());       table.setModel(myCoffeesTableModel);      } catch (SQLException ex) {        JDBCTutorialUtilities.printSQLException(ex);        // Display the error in a dialog box.        JOptionPane.showMessageDialog(         CoffeesFrame.this,         new String[] { // Display a 2-line message           ex.getClass().getName() + ": ",           ex.getMessage()         }       );     }   } 

This method updates the table in the GUI application.

No comments:

Post a Comment