Came across this from the Developer Certification forum, as part of a post under the heading 'nx: contractor - max please help', posted by Mike Southgate with a reply from Andrew Monkhouse, back in 2003:-
Is there a simple box in swing that you can show, like a dialog except that it doesn't require a user response? If there were I could just show it before I do the lock and then make it invisible when I get the lock number. Something like the JOptionPane except without the buttons...
So many options to choose from ....
You could just have a status bar at the bottom of your main window, and put a message in there telling your users what you are doing.
Or you could create a custom JOptionPane / JDialog
Or you could create a custom JWindow
Has anyone implemented anything like the custom JOptionPane/ JDialog or custom JWindow that Andrew suggests?
I maintain an old app that includes functionality for the user to run parameterised searches. User is prompted to enter/lookup parameters to complete a dialog box. Then when they click 'OK' the action validates the input and either presents a dialog to user advising missing/invalid parameter, or displays an animated dialog showing that the search is in progress. This functionality was originally intended to run simple searches (usually single sql statements) so the validation phase is usually very quick; of late, however it has been used for some much bigger multi-sql statement searches, and for these there can be a perceptible delay between invoking the search and user seeing either an 'invalid or missing parameter' dialog or the 'animated running search' dialog. It would seem to be a nice solution to display a simple message 'Initialising Search....' or 'Validating Input.....' when the action is invoked and then hide it when validation fails/the search starts running.
My Swing knowledge isn't that deep but always willing to learn more, all advice/suggestions gratefully received,
Read the section from the Swing tutorial on Concurrency. You could use a Swing Worker.
When you start your task you display the dialog. When you finish the task you hide the dialog.
Joined: Aug 30, 2007
Thanks for your replies.
Randall - is there any way you know of to not display 'OK' or any other options? - i.e. I don't want the 'dialog' aspect of the dialog box, so to speak. If not:-
Rob - the 'animated running search' dialog uses SwingWorker - I guess I can adapt that code to display a similar animated dialog for the validation phase including a 'Cancel' option on the dialog - just seemed like overkill just to display a transient informative message to the user.
Thanks again guys,
Joined: Jun 13, 2009
It is not at all overkill. When you execute a long running task you should always be using a separate thread so you don't block the GUI.
Joined: Aug 30, 2007
Thanks Rob - will be working with your suggestions over the next few days - Cheers Malcolm