While I am searching for better method to exit a Swing Application
in between System.exit(0)
and dispose()
I found a very good answer Here.
Now what I want to add-on is, as I make a call to dispose()
, the current window gets disposed but the JVM takes few more moments while checking for other open frames and threads before it gets exited. I want to show this small amount of time through a dialog saying that : Application is closing...
How can I achieve this?
Asked
Active
Viewed 531 times
3
-
"The JVM takes a few more moments while checking for other open frames..." If you intend to just open a new window/dialog then how should JVM know that this dialog can be disposed but should also be last to be handled? I don't think that you can (cleanly) interfer with the cleanup of the JVM (and you even less should). – Howard Mar 30 '12 at 14:15
-
See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657#9554657) – Andrew Thompson Mar 30 '12 at 14:17
-
Maybe an option is that if you know that substantial cleanup is due to some ressources you allocated before you may create a separate thread which explicitely does the cleanup and shutdown of any thread (which you should do nevertheless) and display the message along that period of time. – Howard Mar 30 '12 at 14:22
-
@Howard -- I can put few more line of code to say that "_Yes it is the last frame_", than what? – Asif Mar 30 '12 at 14:23
-
@AndrewThompson -- I don't have any option to go for _single frame GUI_ – Asif Mar 30 '12 at 14:25
-
*"I don't have any option to go for single frame GUI"* So use dialogs. There were more than 'all in one frame' suggestions in that answer, read it again. – Andrew Thompson Mar 30 '12 at 14:30
-
@AndrewThompson -- I've already only three `JFrame` are there one for `login` and other two for two _different_ kind of `users`..I've used `JTabbedPane` in both `user` windows.. – Asif Mar 30 '12 at 14:43
-
1*"I've already only three JFrame are there.."* That's already 2 too many. *"..one for login"* Modal `JDialog` or `JOptionPane`. *"and other two for two **different** kind of users.."* What is the significance of the word ***different*** as you use it? It seems that most of the types of including more than one layout or functionality in a single GUI can handle *different* types of GUIs. *"I've used JTabbedPane in both user windows.."* Those windows could be `JInternalPanes` (both contained in one `JDeskTopPane` that is added to (one layout constraint) of *one* panel). – Andrew Thompson Mar 30 '12 at 14:51
-
LoginWindow --> `JDialog` (+1 for this, thanks). **different** here used for _different_ functionalities, _different_ authentications, _different_ controls over app, so, _its just me_ who do wants to keep it separate `JFrames` and call it upon login verification. Otherwise, since its _first_ time for me to know something about _Single GUI Application_ I'll definitely apply it in future. :) – Asif Mar 30 '12 at 15:09
1 Answers
3
There is a class WindowUtilities in TUS on sourceforge that I wrote that ALMOST does what you want. You might want to take a look at it and see if you can adapt it for your purposes

ControlAltDel
- 33,923
- 10
- 53
- 80
-
-
my apologies. Actually, the code you'd be interested in is in WindowTiler (same package). Check out the WindowRemover static inner class, as well as the Watch and Unwatch methods in WindowTiler... Sry the code is so ugly ;) – ControlAltDel Mar 30 '12 at 14:31
-
+1 for the code.Thanks. will return to accept your answer if anything good happens for me :) – Asif Mar 30 '12 at 14:36