开发者

JTable and threads

I am using JTab开发者_JS百科le. Many threads will try to add rows to the JTable.

Problem : Only one row gets added. After that, no row gets added.


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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜