aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes is it a single thread or multiple thread for different jframe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "is it a single thread or multiple thread for different jframe" Watch "is it a single thread or multiple thread for different jframe" New topic
Author

is it a single thread or multiple thread for different jframe

sneha kk
Greenhorn

Joined: Aug 03, 2009
Posts: 6
If I have a JFrame (A) within main method and if I create another JFrame or JDialog (B) from an action event from a component wihin JFrame (A), then are A and B going to be two separate threads or are they running under the same thread.

Can anyone point me to any link or explain this kind of scenario...

Thanks.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

It should all run under one thread, the Event Dispatch Thread. Essentially what happens is when you hit a button or some other action or event or whatever happens in Swing, it gets added to a queue of events which Swing needs to handle. The Event Dispatch Thread takes one of these events out of the queue at a time, and dispatches it, in other words, it performs the tasks associated with that event.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
All Swing components should be working on the same thread, the EDT, all listeners call their methods on the EDT. You will have to take care however if you do any background thread work in your app, and be sure that you abide by this rule when calling Swing methods or creating Swing components.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
If you open any Swing component's API it says
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Read the link they provide.
 
Consider Paul's rocket mass heater.
 
subject: is it a single thread or multiple thread for different jframe