dorothy
dorothy

Reputation: 1243

Synchronizing Jtable rows

Just need a general idea how to "synchronize" the updating of rows of a Jtable under SwingWorker.

I have many SwingWorker threads all doing some processing and updating to a single Jtable. Sometimes the display display gets "jumbled" and not what i want.

Say for example:

if ( some condition ) {
  dtm.addRow( ... );   <---- using DefaultTableModel
  dtm.fireTableDataChanged(); <<---- have tried this, but still its jumbled up
  dtm.repaint() ; <<--- have tried this also, to no avail.
}

Usually how would one do this?

thanks

Upvotes: 0

Views: 98

Answers (1)

Jason S
Jason S

Reputation: 189636

I have many SwingWorker threads all doing some processing and updating to a single Jtable.

That sounds like a bad idea. Have the SwingWorker threads communicate with a single entity (e.g. an overseer worker thread, or something in the main thread) which takes care of managing the JTable itself. Then you can use locks or synchronized or whatever to manage concurrent access to state data, and the JTable doesn't have to worry about that.

Upvotes: 1

Related Questions