Link to home
Start Free TrialLog in
Avatar of mwalker
mwalkerFlag for United States of America

asked on

Intermittent JTable refresh problems

I have an applet that displays streaming data vis JMS (i.e. the data in the TableModel is constantly being updated).  The applet has the functionality of changing to a different set of data and updates to it are streamed in.  The problem I see occurring sometimes is that data in the previous TableModel is being displayed in the new TableModel.  I recreate my TableModel (I have a subclass of AbstractTableModel) everytime.  I have made sure that I am removing all TableModelListeners and ActionListener.
When I set the JTable's model to the new TableModel, I always call fireTableDataChanged().  I've even tried to do an applet.repaint() and an applet.revalidate(), but the intermittent problem is still there.

I am using JDK 1.3.002 on a Windows platform.  Is there anyway that I can ensure that the old TableModel is completely removed from the JTable?

Thank you.

Avatar of ozymandias
ozymandias
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not sure about completely removing the TableModel.
What you arec describing shouldn;t happen unless there is a delay between the table data refresh and the table display repaint.

Have you tried calling TableStructureChanged() instead of, or in addition to, TableDataChanged ?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> When I set the JTable's model to the new TableModel,
> I always call fireTableDataChanged

If your calling setModel() then u shouldn't be doing this as you've got a new model.
Though I can't see it would hurt.

> Is there anyway that I can ensure that the old
> TableModel is completely removed from the JTable?

When you set the model, this is handled by JTable.


hi...mwalker,.

if u'r table class object is 'table1' and the tablemodel's is 'tableModel1'.then

u can insert this two lines before every vhange occured in table..

table1.tableChanged(new TableModelEvent(tableModel1));
table1.repaint();

hope u reached somewere near...

Jim
> table1.tableChanged(new TableModelEvent(tableModel1));

Wouldn't recomend calling tableChanged directly, it is intened to only be called by the table model.

> table1.repaint();

This is unnecessary as it is already handled internally by the table.

if the table class is implementing TableModel..then we can call tableChanged method directly..

the repainting is still a bug in JTable,..
if the table class is implementing TableModel..then we can call tableChanged method directly..

the repainting is still a bug in JTable,..
Avatar of mwalker

ASKER

After carefully looking at my code, I realized that I was doing the streaming updates using a SwingWorker thread.  Consequently, one or more of the old threads (created to update the previous view) was still sticking around to update the new view.  I added code in my SwingWorker to make sure that this doesn't happen.  

I tried most of the other suggestions, however, I will accept objects answer since I was using a thread other than the event dispatch thread to update the table.

Thanks for the help.
Thanks for the points :)