• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Problem in SwingUtilities.invokeLater()  RSS feed

 
Girish Varde
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

My application displays 10 rows in a Jtable using AbstractTableModel.These are displayed properly but they are not ediatble if I use SwingUtilities.invokeLater() after show(), which creates a thread.

In this new thread, i am adding some more rows to the table model data. The table data when updated on sreen is editable, but not earlier. In short, when my thread is running, the table/model object(s) is being used and hence locked. The table data is not therefore editable.

I wonder, even though invokeLater() is asynchronous, why is it locking as in case of synchronous case i.e invokeAndWait().

Whwn I use simple Thread().start(), it works fine.

Please help.

Girish Varde
 
Joe Ess
Bartender
Posts: 9414
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
invokeLater() places a method on the Swing event queue. While that method is running on, the GUI is unable to respond to user interaction. If you are just adding items to the table model you can safely do that in a separate thread. Only code directly linked to the GUI (i.e. creating components, executing layout, painting and so on) need execute in the Swing event queue.
Java Tutorial: Creating GUIs with Swing: How to use Threads
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!