Synchronizing modifications of both the model and the view (JTable)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Richard_Braun
Posted On:   Thursday, August 29, 2002 02:57 AM

Hi :-). I have a JTable which is showing the user some data which are actually owned by several threads. When those threads update the JTable to reflect their new state, they call a synchronized method which actually updates the table model (addRow and removeRow mainly). The problem is that even if those managment methods are synchronized, they only protect the model, not the view. As a result I'm getting ArrayIndexOutOfBoundException when a thread removes itself from the table and the view is being refreshed. I tried to synchronize the tableChanged() method by removing the table listeners, and throwing the events manually. This made the exception happen less often, but this is not good enough, since tableChanged() calls a    More>>

Hi :-).


I have a JTable which is showing the user some data which are actually owned by several threads. When those threads update the JTable to reflect their new state, they call a synchronized method which actually updates the table model (addRow and removeRow mainly). The problem is that even if those managment methods are synchronized, they only protect the model, not the view.


As a result I'm getting ArrayIndexOutOfBoundException when a thread removes itself from the table and the view is being refreshed. I tried to synchronize the tableChanged() method by removing the table listeners, and throwing the events manually. This made the exception happen less often, but this is not good enough, since tableChanged() calls a repaint() family method which is also executed asynchronoulsy...


How can I solve this problem ?


Thanks for any answer ;-).

   <<Less

Re: Synchronizing modifications of both the model and the view (JTable)

Posted By:   Mike_Friedrich  
Posted On:   Friday, August 30, 2002 12:44 AM

Have you thought about using one Model per JTable? Do you use SwingUtilities.invokeAndWait and SwingUtilities.invokeLater for your GUI-updates if on a non-event-dispatcher thread?
About | Sitemap | Contact