Efficiently identify modified values in JTable

Hi

I have a table with about 20 columns and 800 rows,

It was read only , now i have open this table for editing.

The user will update cells,and then click update database which will update those cells in database,

is there a efficient way to do this, or do i have to keep old values, and then read all table to compare it with old values to find out which are modified

Is there a row or cell listener which i can use to keep track of cells or rows which where modified,

This should be smart enough to differentiate between just a click and double click for the user to modify this value.

Any ideas or code would help

Ashish

[680 byte] By [kulkarni_asha] at [2007-11-27 8:28:53]
# 1
You can add a TableModelListener to the table's TableModel. That listener will receive notification whenever the table model changes.
dwga at 2007-7-12 20:19:01 > top of Java-index,Desktop,Core GUI APIs...
# 2

One technique is to override the setValueAt( ) method of your TableModel and update the database instantly when the value changes. (Unless this is not the requirement)

Updates to a database record can take just a few seconds so this shouldn't hamper performance. However, you can just as well spawn a new thread and run the update from there.

ICE

icewalker2ga at 2007-7-12 20:19:01 > top of Java-index,Desktop,Core GUI APIs...
# 3

A common design for this is to display a dialog with all the row information when the user double clicks on a row. Then in the dialog the user can change the value and click on the "Update" button.

Otherwise is you want to update everytime data in a cell is changed you can use a TableModelListener.

camickra at 2007-7-12 20:19:01 > top of Java-index,Desktop,Core GUI APIs...
# 4

Hi

I want the users to update all the cells they want and then click on update this button, then only pick those rows updated and update the database

i think i will write a TableModelListener and store only the rows updated in List and then update data when user clicks update

Does this look like a good solution

kulkarni_asha at 2007-7-12 20:19:01 > top of Java-index,Desktop,Core GUI APIs...