Solved

Intermittent JTable refresh problems

Posted on 2001-07-20
9
1,196 Views
Last Modified: 2013-11-23
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.

0
Comment
Question by:mwalker
9 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 6303631
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 ?
0
 
LVL 92

Accepted Solution

by:
objects earned 150 total points
ID: 6304056
Are you updating your model from a thread other than the event dispatch thread.
Swing is single threaded, and their are only a few operations that are thread safe.
So you need to ensure you do all your gui updating from the Swing thread (unless the javadoc says the method is threadsafe).
There are a couple of methods in SwingUtilities which help, invokeLater(), and invokeAndWait().
0
 
LVL 92

Expert Comment

by:objects
ID: 6304059
> 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.


0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 1

Expert Comment

by:jimaricat072100
ID: 6304324
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
0
 
LVL 92

Expert Comment

by:objects
ID: 6304359
> 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.

0
 
LVL 1

Expert Comment

by:jimaricat072100
ID: 6304462
if the table class is implementing TableModel..then we can call tableChanged method directly..

the repainting is still a bug in JTable,..
0
 
LVL 1

Expert Comment

by:jimaricat072100
ID: 6304523
if the table class is implementing TableModel..then we can call tableChanged method directly..

the repainting is still a bug in JTable,..
0
 

Author Comment

by:mwalker
ID: 6308950
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 6310415
Thanks for the points :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question