• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does Swing component initialization have to occur on the EDT?

 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example:



Must the initialization of a Swing component occur on the EDT or may the initialization occur on any thread? Obviously altering the components later needs to be on the EDT, showing a JFrame for example or changing the Border of a JComponent. I would have expected the initialization to be safe, but now that I encounter even more lunacy in Swing I'm not so sure. If this must occur on the EDT, how do you achieve it? I find invokeLater() unacceptable as it means the current thread can return with a reference to our created class where the members of that class have not necessarily been initialized, so I'd have to do something like this:



That would force me to make field non-final unnecessarily. The only option that would leave me with is throwing an exception if it was created outside the EDT, which may cause a lot of unnecessary headache for clients that wish to create it and constantly have to shift the creation to the EDT.

Please tell me the initialization is thread-safe at least.
 
reply
    Bookmark Topic Watch Topic
  • New Topic