I want to accomplish the following: user clicks to close a JFrame, then a JDialog popups up display an indeterminate JProgressBar for 3 seconds, then close the popup, close the JFrame. What's the best practice here? I tried this. But the popup dialog doesn't show the progressbar. I'm guessing that I'm not doing the threading correctly. What's wrong with my code?
thank you both for the help. Craig, I tried your code and it works fine except that the when user clicks to close the window, the window closes. and then the progress dialog will be displayed for 3 seconds before disappearing. Is there a way to delay the window from closing for 3 seconds as well?
Rob, I tried your SwingWorker code and the progress dialog closes rightaway without waiting for 3 seconds. any idea why?
posted 11 years ago
Rob, nevermind, your code works fine. The key is to make the progress dialog modal, otherwise when I close the window, the dialog gets closed rightaway too.
Correct. Non-modal dialogs will not block on their setVisible method, so the windowClosing method finishes and the window is closed.
By the way, I'm sorry for the compiler errors in my code; it was just quickly copied from Craig's code and modified a bit; moving code around failed to rename some stuff
And I noticed the dialog does not center around the frame, but a simple call to dialog.setLocationRelativeTo(frame) will do that for you.
If you want to remove the close button etc of the dialog, you can call setUndecorated(true) on it. You should call this before pack() because it will fail for realized windows. Check the API for more info. [ October 24, 2008: Message edited by: Rob Prime ]