Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

JOptionPane blocking the event dispatch thread

Thread view: 
BPS - 18 Mar 2004 03:00 GMT
I've been studying the example at

  http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

and there's something I can't figure out.

The Example2 pane pops up a JOptionPane that is documented
to block the current thread.  This dialog is popped up on
the event dispatch thread (I've checked).  Yet, the event
dispatch thread continues to update the progress bar in
the Example1 pane (I've checked this as well).

How is the event dispatch thread able to update the progress
bar while it is supposed to be blocked by the JOptionPane.

Thanks,

Benji
Thomas Weidenfeller - 18 Mar 2004 09:05 GMT
> The Example2 pane pops up a JOptionPane that is documented
> to block the current thread.

This is an oversimplification. But first, JOptionPane is a subclass of
JDialog. And it is JDialog which contains the code for handling modal
window. For modal windows it checks if the current thread is the event
dispatching thread. If this is the case, it changes the event pump and
continues to pump events. It has to, otherwise no one could handle the
button events on the modal dialog. So you couldn't close a modal dialog :-)

The source code of JDialog is enlightening. You might want to spend a
few minutes and read through the parts related to modal window handling.
The source code comes with every Sun SDK in the file src.zip (or .jar in
older SDKs).

/Thomas
Babu Kalakrishnan - 18 Mar 2004 16:12 GMT
>> The Example2 pane pops up a JOptionPane that is documented
>> to block the current thread.
[quoted text clipped - 3 lines]
> The source code comes with every Sun SDK in the file src.zip (or .jar in
> older SDKs).

A small correction, Thomas. It is actually the code in the
java.awt.Dialog class that performs this magic - JDialog just inherits
it. The OP can refer to the show() method in the source code of
java.awt.Dialog for details.

BK
BPS - 18 Mar 2004 17:10 GMT
Thank you both so much!  I will look at that code.

Cheers,

Benji


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.