Tabel is not refreshed instantly
I have a JTable in a JPanel. There is an Edit button in the panel. Through the Edit button I can edit any selected row of the table. If Edit button is clicked, and new values are provided in the appeared dialog box, then the selected row is updated. but the table does not show the newly set value instantly. If i click anywhere in the table, only then the new value is shown. This is really frustrating.
after updating the table model i use:
table.invalidate()
panel.validate() //panel where the table is attached
as i know this is supposed to work. I have other Add and Delete buttons. They dont create any problem. I dont find any error in the code. Other expert also have not found any error. I have tried different ways but in vain
[768 byte] By [
shihab99a] at [2007-10-2 7:20:57]

What kind of model is it? What do you extend?How are you updating the model? Which events are you fireing?Kaj
kajbja at 2007-7-16 20:56:58 >

I am using a custom table model extending AbstractTableModel. I simply use array for data storage inside my table model.
Then just invoke public void fireTableRowsUpdated(int firstRow, int lastRow)after you update the value in the model.
In the setValueAt(..) method of your Table model add the following code - fireTableDataChanged after you have saved the changes. It should work after that.
> In the setValueAt(..) method of your Table model add
> the following code - fireTableDataChanged after you
> have saved the changes. It should work after that.
Only the public void fireTableRowsUpdated(int firstRow,
int lastRow)
method needs ot be invoked! No need to use a bomb!
I really dont understand why it is not working. I have called fireTableRowsUpdated(<indexof the row>, <indexof the row>) after updating the table model. I dont find any change.
> I really dont understand why it is not working. I> have called fireTableRowsUpdated(<indexof the row>,> <indexof the row>) after updating the table model. I> dont find any change.Post your setValueAt(..) method.
void edit(int index,String[] p)
{
if(index>=data.length) return;
data[index]=p;
save();
}
This is inside my table model. "data" stores data of the table. save() is not very important thing to know. fireTableRowsUpdated() is called from the actionPerformed() method of the Edit Button. It is called after the actual edit of the table model.
> fireTableRowsUpdated() is called from the> actionPerformed() method of the Edit Button. It is> called after the actual edit of the table model.You should do that in the setValue method of your model.Kaj
kajbja at 2007-7-16 20:56:58 >

> void edit(int index,String[] p)
>{
> if(index>=data.length) return;
> data[index]=p;
> save();
>}
>
> This is inside my table model. "data" stores data of
> the table. save() is not very important thing to
> know. fireTableRowsUpdated() is called from the
> actionPerformed() method of the Edit Button. It is
> called after the actual edit of the table model.
Normally, fireTableRowsUpdated() should be fired in your setValueAt(..) method in your table model immediately after you updated the value BUT since for some reason you are not editing table values directly then I would expect you to fire the event as the very last thing you do in the method that updates the table model (presumably at the end of your your edit() or save() methods).
I would not expect you to invoke fireTableRowsUpdated() from your actionPerformed() method!
> > fireTableRowsUpdated() is called from the
> > actionPerformed() method of the Edit Button. It is
> > called after the actual edit of the table model.
>
> You should do that in the setValue method of your
> model.
>
> Kaj
Kaj, the OP does not seem to be using setValue() method because he is not editing the table directly!
> Kaj, the OP does not seem to be using setValue()> method because he is not editing the table directly!Ah, I didn't read the part where he said that the edit method came from the model. I thought that was part of the code which later on called the setValue method.
kajbja at 2007-7-16 20:56:58 >

I have tried all. Nothing helps. No change
> I have tried all. Nothing helps. No changeAnd you are 100% sure that the fire method is called, and that it's called with the correct arguments? Have you verified this in a debugger or by printlines?Kaj
kajbja at 2007-7-16 20:56:58 >

You people are absolutely right. Problem is in jdk1.4 it does not work, i dont know why but in jdk1.5 it works perfectly.
> You people are absolutely right. Problem is in jdk1.4> it does not work, i dont know why but in jdk1.5 it> works perfectly.Strange. It should work in JDK 1.4 as well.Kaj
kajbja at 2007-7-20 19:16:43 >

> You people are absolutely right. Problem is in jdk1.4> it does not work, i dont know why but in jdk1.5 it> works perfectly.Funny, most of my old clients are usng 1.3.1 or 1.4.1 and it works OK for them!