How can I make my application pause when I open custom JDialog and after the dialog is closed to make continue again.
In Java, we can use TimeUnit. SECONDS. sleep() or Thread. sleep() to pause a program for a few seconds.
JDialog(Dialog owner, boolean modal) Creates a dialog box with the specified Dialog owner and modality. JDialog(Dialog owner, String title) Creates a modeless dialog box with the specified Dialog owner and title.
Simply use:
setModal(true);
I usually call it from within the constructor of the JDialog
.
See the Javadocs on setModal(boolean)
.
http://java.sun.com/javase/6/docs/api/java/awt/Dialog.html#setModal(boolean)
That will cause execution to block on the current thread until the dialog box closes.
Alternatively, you can use:
setModalityType(Dialog.DEFAULT_MODALITY_TYPE);
It is equivalent to setModal(true)
and technically the correct way to do it.
See the constructor of JDialog. You can set the modality of this dialog. Setting modal=true will pause your application. You can also use the method setModal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With