
Signature
Unemployed English Java programmer
> Contrary to other reports I believe it is possible.
>
> As I understand it: There is a hack for dialogue boxes to run an event
> loop. Some API allow an application developer to open a dialogue box
> from the Event Dispatch Thread (EDT) and wait for it to be closed. Some
> magic going on there obviously.
It is not magic. It is just that the event pump is replaced, so only
events for the modal dialog are pumped. There are maybe 5 to ten lines
of code involved in the Dialog source code to make the dialog modal.
> IIRC, Foxtrot (google it) exploits
> dialogues to give a nice interface to this functionality.
>
> Having said that, it is very much cleaner to use separate threads. Just
> be very, very careful.
I find it rather hilarious that Foxtrot claims to replace Threads by
using - well you guessed it - a worker Thread.
I still prefer the classic way:
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
public void run() {
//
// Do some time consuming task
//
...
//
// Update the GUI from within the task
// synchronous: invokeAndWait()
// asynchronous: invokeLater()
//
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//
// GUI code
//
}
});
}
}).start();
}
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Thomas Hawtin - 15 Jul 2005 15:12 GMT
> It is not magic. It is just that the event pump is replaced, so only
> events for the modal dialog are pumped. There are maybe 5 to ten lines
> of code involved in the Dialog source code to make the dialog modal.
Looking at the source of java.awt.Dialog.show, I'd call that magic. It's
huge and it uses non-public interfaces.
Technically there are events other than for the modal dialog that are
let through. For instance repaints.
> I find it rather hilarious that Foxtrot claims to replace Threads by
> using - well you guessed it - a worker Thread.
"Foxtrot is a small but powerful framework for using threads with the
JavaTM Foundation Classes (JFC/Swing)."
-- http://foxtrot.sourceforge.net/docs/introduction.php
> I still prefer the classic way:
Absolutely. Like that or with queues or similar. I tend to have the
non-EDT task and the invokeLater task separate.
What I really don't like about the Foxtrot approach is that the causing
event hasn't finished executing (obviously). So now you have problems of
listeners that haven't fired and of re-entrancy.
Tom Hawtin

Signature
Unemployed English Java programmer