tags:

views:

1085

answers:

3

Hi there I am working on an Java Swing application that performs a search on a database. It has 2 JDialog boxes that popup during the search.

The first tells the user that the search has started and has an OK button to close. The second tells the user that the search has returned and is also closed by hitting the OK button.

I there a way of closing the first JDialog box programatically, when the search returns, it's it will be pretty obvious that the seach was started by the time the search has returned.

Thanks.

A: 

call the.dispose() method on the JDialog.

nos
Thank's. Do you know how to get access to the currently displayed JDialog object however? The framework I am using doesn't keep a reference to the dialog objects it creates. Thanks.
Dave
You should keep a reference to it when you create it. Probably you can create only one for the whole life of the application (unless you need two searches running at once).
DJClayworth
+2  A: 

Even though closing dialog is as simple as calling setVisible(false) on it, I think your approach is not user intuitive. Showing two dialogs is a bad UI practice. What you have to do is to show progress animation/dialog. Once your search returns stop the progress animation/dialog and show the data returned. Here are some links about the subject:

http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html http://developerlife.com/tutorials/?p=248

eugener
Using a progress dialog makes the whole request/response process synchronous, in that the user must sit and watch the progress bar until the results have returned. Using two dialogs allows the user to do other things whilst awaiting the results.A better solution would probably be to have the first dialog close automatically after a timeout (if the user doesn't close it himself before then).
DaveJohnston
There is no need for the dialog to be modal.
DJClayworth
A: 

Check out my answer on another similar question.

Savvas Dalkitsis