This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 3575
    
  14

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: 37926
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: is it a single thread or multiple thread for different jframe
 
Similar Threads
Thread doubt
JFrame ?!!!
closing jframe with button question.
what is happening, iam unable to see
few Qs on serialVersionUID