Update table in another thread

Y

Yamin

Hi all,

Okay, first off. Thanks for all the comments on my JLable.setText
question.
Anywhose, it seems the same pattern of updating swing components in
other threads is followed in many other classes in the code I have to
deal with.

But anyways, for my project I have the oppurtunity to do things
safely. The one aspect that got me thinking though was updating a
JTable from another thread. These tables are going to be large ( >15
columns, a thousand rows perhaps). And data will always be very
often. At least a few times a second (not the whole table of course).
The user will NOT be able to edit the data from the table. Its read
only. My initial instinct is as follows.

class myDataObject //synhronized container with read/write methods

class myTableModel extends AbstractAbstractTableModel
//calls myDataObject for getValue...
//does invokeLater for fireevents

anyone forsee any issues with this or have other suggestions?
 
Y

Yamin

Okay, I think I found a good solution.
I found it on comp.lang.java.gui "How to make table model thread
safe?", sept 10, 2000.

Essentially, what it does is the model 'belongs' to the GUI thread.
'Messages' are sent as updates via invokelater so the actual updates
on the table data are done in the GUI Thread.

This way, there is blocking or synchronization. The worst that could
happen is a backlog of messages. But if that becomes an issue, I'll
'package' messages into batches.

Yamin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top