简体   繁体   中英

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

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?

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
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM