Waiting for a dialog to close

I created my own file chooser (for choosing remote files) and need to cause execution to "pause" while the user is looking for a file (while the file chooser dialog is still open) just like JFileChooser.showOpenDialog() does.

Here is what my code looks like (somewhat):

RemoteFileChooser fileChooser =new RemoteFileChooser(this,true);

fileChooser.showOpenDialog();

RemoteFile f = fileChooser.getSelectedFile();

The problem is that the third line is executed immediatly after the dialog is opened. I need it to be executed only after the fileChooser dialog has closed.

I know that this can be done by using a separate thread to show the dialog and by making the main thread sleep while the dialog is open, but would like to, if possible, keep my code as simple as possible (no multithreading). I looked through JOptionPane's source code to find out how it (and JFileChooser) pause the execution but couldn't find anything (with my level of understanding).

I've also searched these forums and Google but all I get is people talking about modal dialogs (which are what I am already using) and extremely unclear explanations. Any help on this would be greatly appreciated.

Thanks

[1303 byte] By [spamKillera] at [2007-10-3 2:50:13]
# 1
hi!is RemoteFileChooser instance of Dialog / JDialog, if so, is it Modal? check for the modality..:)
Aniruddha-Herea at 2007-7-14 20:39:02 > top of Java-index,Desktop,Core GUI APIs...
# 2

Its actually pretty difficult to make a fully modal object without basing it on JDialog, which uses a lot of interal stuff which isn't readilly accessible.

What wil usually serve, though, is to make your dialog what I call "Thread modal", i.e. cause the thread that calls it to wait until it's closed. Of course you mustn't then call it from the dispatcher thread, but start a worker thread to handle your file request.

Do something like this:

public class RemoteFileChooser ...... {

boolean finished = false;

RemoteFile chosen = null;

.....

private synchronized void done() {// called by OK and Cancel handler

finished = true;

notifyAll();

}

public RemoteFile getSelectedFile() {

synchronized(this) { // wait until dialog finished

while(!finished)

wait();

}

return chosen;

}

malcolmmca at 2007-7-14 20:39:02 > top of Java-index,Desktop,Core GUI APIs...
# 3

Yes, I am using JDialog, but It seems that there is something wrong with the way I am using it. I created a new class to test a modal dialog and it works perfectly, so it shouldn't be hard at all getting this to work.

Thank you very much for your time though, and sorry for asking this without properly testing it out first.

spamKillera at 2007-7-14 20:39:02 > top of Java-index,Desktop,Core GUI APIs...
# 4
you can check in the constructor of your own class, what are you passing to the super? it may so happen that you are sending false in the super(owner, a_bModal). it may be very simple.:)
Aniruddha-Herea at 2007-7-14 20:39:02 > top of Java-index,Desktop,Core GUI APIs...