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]
# 1
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 > top of Java-index,Java Essentials,Java Programming...
# 2
I am using a custom table model extending AbstractTableModel. I simply use array for data storage inside my table model.
shihab99a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 3
Then just invoke public void fireTableRowsUpdated(int firstRow, int lastRow)after you update the value in the model.
sabre150a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 4
In the setValueAt(..) method of your Table model add the following code - fireTableDataChanged after you have saved the changes. It should work after that.
Muyeena at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 5

> 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!

sabre150a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 6
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.
shihab99a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 7
> 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.
sabre150a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 8

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.

shihab99a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 9
> 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 > top of Java-index,Java Essentials,Java Programming...
# 10

> 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!

sabre150a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 11

> > 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!

sabre150a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 12
> 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 > top of Java-index,Java Essentials,Java Programming...
# 13
I have tried all. Nothing helps. No change
shihab99a at 2007-7-16 20:56:58 > top of Java-index,Java Essentials,Java Programming...
# 14
> 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 > top of Java-index,Java Essentials,Java Programming...
# 15
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.
shihab99a at 2007-7-20 19:16:43 > top of Java-index,Java Essentials,Java Programming...
# 16
> 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 > top of Java-index,Java Essentials,Java Programming...
# 17
> 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!
sabre150a at 2007-7-20 19:16:43 > top of Java-index,Java Essentials,Java Programming...