Re: SwingWorker.execute() does nothing



Thomas Kellerer wrote:
Ben Phillips, 08.10.2008 08:45:
I've got a strange app hang. A particular button click pops up a modal "Please Wait" dialog, then constructs a SwingWorker implementation and calls execute() on it. The done() method removes the dialog.

When you call setVisible(true) on a modal dialog, your code will stop until the dialog is closed. So if you call SwingWorker.execute() after setVisible(true) the execute() will not be called until the dialog is closed.

Really? What idiot made that boneheaded design decision -- and, moreover, didn't document it anywhere?

I'll see if simply swapping the setVisible(true) to after the execute() fixes things. I definitely don't want the UI to receive input events while this work is going on, but I don't want it to hang (not paint properly) either, and eventually I might want to put a working Cancel button on the "Please Wait" dialog too. (Were it not for those considerations, I'd just have the work done on the EDT and the heck with it!)
.