tags:

views:

101

answers:

1

Hey Guys
I am doing project on java.
In one of the class, I am working on jtable.
Now what i am doing is,

  • In the table data will be loaded from the database.

Now i want to change some value at some exact row and column.

so for that i am using jtable's setValue function. which is like this....

grayCardTbl.setValueAt(Float.valueOf(String.valueOf(pdiff)),1,4);

I have checked the "pdiff" variable, it is perfect.

i had total 5 columns and 10 rows. So now problem with rowindex and column index.

and after this i have also refresh the table. but still it is not reflecting on table.

A: 

The JTable.setValueAt(...) method calls TableModel.setValueAt(...).

My guess is that you've not implemented it in the model and the data doesn't get updated.

Edit: if your model calls JTable.setValueAt(...), it's going to loop into a stackoverflow. What you need to do is actually update the underlying data.

For instance if your model's getValueAt(...) does return data[row][column], then setValueAt(...) needs to do data[row][column] = value;

Guillaume
I had written something like this...in setValueAt()..........public void setValueAt(Object aValue, int rowIndex, int columnIndex) {if(columnIndex == 4){ this.table.setValueAt(Float.valueOf(String.valueOf(aValue)), rowIndex, columnIndex); table.tableChanged(new TableModelEvent(this)); }}
Nitz
yeap...i had solved it....thanks 4 replay....
Nitz