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 / May 2006

Tip: Looking for answers? Try searching our database.

Displaying a Modal JDialog with a background thread?

Thread view: 
Leif Bloomquist - 29 May 2006 20:38 GMT
Hi all,

In my Swing application I have a JButton on a JPanel that tells the program
to save a large array of data to disk.  The process takes about 10 seconds,
so I pop up a simple JDialog showing how far along the process is.  I'm
creating and showing the JDialog, then using SwingWorker() to do the save as
a background thread so the UI thread doesn't hang.  Inside construct() I'm
updating a JLabel on the JDialog with some descriptive text about where it
is in the process.  This works perfectly.

But I have a bit of a Catch-22 situation.  Since the JDialog isn't modal,
it's still possible to click the JButton "underneath" the JDialog and start
*another* thread doing exactly the same thing in parallel.  Not good.

However, if I set the JDialog to be Modal, the main thread stops when
.setVisible() is called, of course.  So the background thread never gets
started.

Any suggestions?  Is there a better way to go about this?

Thanks much,
Leif

Signature

Leif Bloomquist
leif (at) schema factor (dot) com
http://home.ica.net/~leifb/

"Once secure, saturate the area with plasma mortars and spicy barbecue
sauce."

Knute Johnson - 29 May 2006 22:09 GMT
> Hi all,
>
[quoted text clipped - 18 lines]
> Thanks much,
> Leif

Sure, start the background worker thread and then open your modal dialog.

Signature

Knute Johnson
email s/nospam/knute/

Andrey Kuznetsov - 29 May 2006 22:45 GMT
>> But I have a bit of a Catch-22 situation.  Since the JDialog isn't modal,
>> it's still possible to click the JButton "underneath" the JDialog and
[quoted text clipped - 11 lines]
>
> Sure, start the background worker thread and then open your modal dialog.

or disable your button instead

Andrey

Signature

http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities

Leif Bloomquist - 30 May 2006 14:35 GMT
> Sure, start the background worker thread and then open your modal dialog.

Ah!  I should have thought of that.  This worked perfectly, of course.  Many
thanks!


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.