My application sends data to the gui frequently, but not constantly. So
far, my implemenation of wait/notify on a linked list of arriving data has
worked fine. Now I need to update a JTable based on incoming data. I'd
like the JTable cell values to change based on incoming data. However, I'm
uncertain where to put run method with the wait.
Most of my GUI objects have the following code:
public void run() {
synchronized( myQueue ) {
try {
myQueue.wait();
}
catch (InterruptedException e) {
cat.warn("Exception: " + e + " while waiting on myQueue"); }
while ( myQueue.size() > 0 ) {
object = myQueue.removeLast();
// *** update the gui with object ***
}
}
}
Should I create a tableModel that implements runnable and uses setValueAt to
update cells? For example:
public class myTableModel extends AbstractTableModel implements Runnable {
public void run() {
synchronized( myQueue ) {
try {
myQueue.wait();
}
catch (InterruptedException e) {
cat.warn("Exception: " + e + " while waiting on myQueue"); }
while ( myQueue.size() > 0 ) {
object = myQueue.removeLast();
// **** call setValueAt( object )
}
}
}
Thanks
Jeff
--
Todd Corley - 17 Dec 2003 18:18 GMT
> My application sends data to the gui frequently, but not constantly. So
> far, my implemenation of wait/notify on a linked list of arriving data has
[quoted text clipped - 43 lines]
> Jeff
> --
Swing is not thread safe. If you are going to update a swing
component use:
javax.swing.SwingUtilities.invokeLater( Runnable runnable )
Your actual usage will look something like :
while ( myQueue.size() > 0 ) {
object = myQueue.removeLast();
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
// **** call setValueAt( object )
}
});
}
InvokeLater runs the runnable in the event thread. Which is where
swing updates are supposed to happen.
Hope this helps,
Todd