Reputation: 243
I am using JTable. Many threads will try to add rows to the JTable.
Problem : Only one row gets added. After that, no row gets added.
Upvotes: 0
Views: 627
Reputation: 324118
Only one row gets added. After that, no row gets added.
Probably because you recreate the TableModel every time, or you have multiple references to the TableModel and your code is updating the wrong model.
Upvotes: 0
Reputation: 74760
Swing is generally not thread-safe. If you need to modify Swing components from Threads other than the AWT Event-dispatch-Thread, use
SwingUtilities.invokeLater(new Runnable(){public void run() {
// here your modification code
}});
Alternatively invokeAndWait
. (These methods in fact do the same as the like-named methods in java.awt.EventQueue
.)
Upvotes: 2