Solved

Intermittent JTable refresh problems

Posted on 2001-07-20
9
1,191 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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
 
LVL 1

Expert Comment

by:jimaricat072100
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 92

Expert Comment

by:objects
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the points :)
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now