1

Let's say I change a cell with value "old" to "new". This will invoke tableChanged(TableModelEvent). How do I retrieve the value that the cell had before "new"(which should be "old")?

I thought about making a copy of TableModel of my JTable,but is there a simpler and smarter way to do this?

Thanks in advance!

Fermat's Little Student
  • 5,549
  • 7
  • 49
  • 70
  • 1
    By the time `tableChanged` has being fired, it's to late, the value has changed. About the only place you can catch this is in the `setValue` method of the table model. I'd simply have a map in the model keyed to the column name that maintains a pair of objects, the old and new value, which you can look up – MadProgrammer Oct 15 '12 at 03:56
  • 3
    Also see [JTable: Detect cell data change](http://stackoverflow.com/q/6889694/1048330). – tenorsax Oct 15 '12 at 03:58
  • 1
    Why and what exactly are you trying to achieve? – kleopatra Oct 15 '12 at 10:23

1 Answers1

0
Try this when your table loads first time 
int row1=table.getRowCount();
        int column=table.getColumnCount();
        val=new Object[row1];
        val1=new Object[row1];
        for(int j=0;j<row1;j++){
            val[j]=table.getValueAt(j, 0);
            val1[j]=table.getValueAt(j, 1);

        }
ravibagul91
  • 20,072
  • 5
  • 36
  • 59