Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

JTable & TableSorter & TableModel & frequently changing data

Thread view: 
Bernhard Pauler - 04 Jan 2005 10:25 GMT
Assuming you have the following classic combination of ...
*) a JTable,
*) a TableSorter and
*) a TableModel

Furthermore the data of your TableModel is frequently changing like this:

TableModel:
public void addRecord(Record Record) {
    data.add(record);
    fireTableDataChanged();
}

The invocation of fireTableDataChanged() notifies all listeners that the
model has changed. If a TableSorter is linked between the model and the
view it will receive the notification.

My question is:
If you are changing the model (as shown in the example method above) it
has to be done one AWT-event-thread, right? If the model is frequently
changed, do I have to wait until one event is completely processed thus
changing the model step by step, waiting each time until each listener
has reacted to the change.

I ask this question because I have some nasty problems. Exceptions like
ArrayOutOfBoundsException in TableSorter or exceptions while iterating
through the data container of the model, all occurring on the
AWT-event-thread. I can imagine that the following things happen:

1. Method addRecord is invoked, changing data in the container of the
model and notifying listeners.

2. While notifying the listeners of the former change to the model the
method addRecord is invoked again changing the data. Listeners like
TableSorter stumble because they process a former notification with data
of a latter change.

Could that be?

Thanks for any help,

Bernhard
Christian Kaufhold - 07 Jan 2005 16:33 GMT
> public void addRecord(Record Record) {
>        data.add(record);
>        fireTableDataChanged();
> }

Why are you not using fireTableRowsInserted?
(assuming a record consists of a rows).

> The invocation of fireTableDataChanged() notifies all listeners that the
> model has changed. If a TableSorter is linked between the model and the
[quoted text clipped - 3 lines]
> If you are changing the model (as shown in the example method above) it
> has to be done one AWT-event-thread, right? If the model is frequently

Yes.

> changed, do I have to wait until one event is completely processed thus
> changing the model step by step, waiting each time until each listener
> has reacted to the change.

What do you mean by "one event is completely processed"?

> I ask this question because I have some nasty problems. Exceptions like
> ArrayOutOfBoundsException in TableSorter or exceptions while iterating
[quoted text clipped - 6 lines]
> 2. While notifying the listeners of the former change to the model the
> method addRecord is invoked again changing the data. Listeners like

How is that supposed to happen (if the event-dispatch thread is notifying
the listeners, how can at the same time addRecord be invoked)?

Christian
Bernhard Pauler - 13 Jan 2005 13:27 GMT
> What do you mean by "one event is completely processed"?

EventQueue.invokeAndWait(Runnable runnable)

> How is that supposed to happen (if the event-dispatch thread is notifying
> the listeners, how can at the same time addRecord be invoked)?

If another thread would deliver new data. But since the addRecord(...)
method with its call fireTableRowsInserted should only be invoked by the
AWT-event-thread this should not happen. You are right. Thank you.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.