JTable – Detecting User Edits

So, I want to present the SQL database tables to the end user for editing in my Roms Manager program.  I’ve got the first table displaying in it’s edit window with the SQL backend correctly queried:

I’ve strugged to get the propertyChanged listner to properly give me what I need from cells being edited and changed.   Then I found this excellent post over at: https://tips4java.wordpress.com/2009/06/07/table-cell-listener. A nice table listener class to import into my application package. Just added the following code to the table and I suddenly had easy access to the underlying table data for manipulation:

Action action = new AbstractAction()
{
    public void actionPerformed(ActionEvent e)
    {
        TableCellListener tcl = (TableCellListener)e.getSource();

        //INSERT CODE HERE TO UPDATE H2 DATABASE
        // tcl.getRow());
        // tcl.getColumn());
        // tcl.getOldValue());
        // tcl.getNewValue());
    }
};

TableCellListener tcl = new TableCellListener(genreTable, action);

Leave a Reply

Your email address will not be published. Required fields are marked *