• Post Reply Bookmark Topic Watch Topic
  • New Topic

Prevent repaint while rearranging a TableModel

 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with quite complex TableModels which sometimes rearrange their data on certain events. When a repaint occurs during that rearrangig, the Model might be inconsistent and getValueAt() delivers wrong values. Can I prevent the repaint while rearranging? Or are there any other suggestions?

Here's some simplified(!) code as an example - my actual TableModels are much more complex.



I'd appreciate a solution without synchronized methods in it (if there is any)

Sven

>
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do the rearranging on the Event Dispatcher Thread (EDT) you'll need no synchronization, since the repainting will also be done on the EDT. If not then you'll need to synchronize, or rebuild the table model while it is detached from the table.

The second option basically means that instead of rearranging your existing model, you create a new model with the rearranged data. Since this has no GUI interaction you can do this in a background thread. When done you then replace the table's model on the EDT. If you use a SwingWorker you can use the "done" method for that. The downside to this approach is that you'll have to redo a lot of configuration to the table. The table column model is rebuilt so any renderer / editor added to a TableColumn is discarded.
 
Sven Farrenkopf
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, running it on EDT did the trick!

Thanks!

Sven


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!