Current position:  Home > Default > Need a help on TableModelListener.

Need a help on TableModelListener.

Time:November 30
Advertisement
Hi,
I need a help on TableModelListener.
I have a table in which i have some Double vaules and in a textfield i am summing up the values.
This table have thousands of record. Already i am summing up the values using for loop and same when i update any value of it.
So i am searching for a better way. Like pre-event handling. For which i can get a value for a cell before editing and after editing or cell value for row that is deleted.
Advertisement
We can do sum calculation directly in the TableModel. The method "setValueAt" of the TableModel is called after each cell editing. We can override it to do anything we want with the old value stored in the model and the new value passed into the method through the parameter list. When deleting a row, we also call some method of the model (something like "removeRow") and there again we can do anything we like with the old value before deleting it.