Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

in which thread shoud I use dialogs?

0 views
Skip to first unread message

Marteno Rodia

unread,
Dec 23, 2009, 5:44:36 AM12/23/09
to
Hello,
An old Swing's rule says that all the UI operations should be carried
out in the event-dispatching thread, and other operations should be
done in other threads. I have written a GUI application which uses
multiple threads. Among them, there is a SwingWorker thread which can
inform user about an error, using a dialog for this purpose. Following
the aforementioned rule, I don't create the dialog in the SwingWorker
thread, but I put a new Runnable object in the Events' Queue.

In such context, I'm facing a great doubt: what if the dialog waited
for user's input? (some dialogs can do this, e.g. file chosers).
Wouldn't they blocked the event-dispatching thread?

regards,
Marcin

Lew

unread,
Dec 23, 2009, 9:56:06 AM12/23/09
to

No. Classes like JDialog are designed to work with other objects on the EDT.
Modal dialogs block certain activities to the user, such as switching to a
different frame, but Swing does that by managing its own internal state. How
it ignores or eats the particular events can be a black box to us as
programmers. If we put our GUI on the EDT, Swing takes care of the rest.

Googling shows that this question is a FAQ. I didn't find in a quick search
whether Swing just handles modality in its main event loop or spawns a
hijacking thread. ISTR reading somewhere, somewhen that it's the latter.

--
Lew

Lew

unread,
Dec 23, 2009, 10:00:03 AM12/23/09
to
Marcin Rodzik wrote:
> An old Swing's rule says that all the UI operations should be carried

Please do not multipost.

--
Lew

0 new messages