• Post Reply Bookmark Topic Watch Topic
  • New Topic

swing+threads

 
G�tz Wankelmuth
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I launch a swing application, the GUI runs in a separate thread. Why should I construct my own Runnable and call ...InvokeLater() - as recommended in the Sun Tutorial ?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The recommendation is given in the note that follows the first paragraph under the header "The Event-Dispatching Thread" on How to Use Threads. If components begin sending events to event listeners before the initial state of your app is complete it can cause trouble. This often happens with ComponentListeners and MouseMotionListeners. It can happen with listeners being added before components have been initialized during construction and with certain uses of threads. There are a lot of ways to get into trouble like this so it's easier for the designers to say "always do this and you'll be safe" than to try to explain everything that could possibly go wrong. Careful design is the alternative.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!