How can I do something before setValueAt is carried out in my AbstractTableModel?

30 Views Asked by At

I have a JTable in my Client class. This JTable is given a model, myModel, which extends from AbstractTableModel. I need to control when setValueAt is executed. Right now if I click on a (modifiable) row on my JTable, it automatically does setValueAt at enter. What I want to do is only carry out SetValueAt IF I can update the SQL Database with the change in this row of an SQL table. So if SQL throws error on the update, then I want setValueAt to not happen...

How would I do this from the Client instance? How would I listen to when it wants to run setValueAt?

1

There are 1 best solutions below

0
Trapoc On

I have managed to solve it by overriding my setValueAt from the client side, which enables me to do the SQL query from inside of the client rather than my table model, where I already have all the connections to do a query setup.

new myModel() {
    @Override
    public void setValueAt(Object aValue, rowIndex, columnIndex) {
         //query executed, and then we can update
    }
}