Solved

Intermittent JTable refresh problems

Posted on 2001-07-20
9
1,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

635 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