Solved

Intermittent JTable refresh problems

Posted on 2001-07-20
9
1,199 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 77
Java: The Public Class Main 4 66
ejb entity bean example 2 57
Coding for the first time 9 100
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

739 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