How to pause execution when JDialog is open

How can I make my application paused when I open a custom JDialog and after closing the dialog to continue.

+6
java swing
source share
2 answers

Just use:

setModal(true); 

I usually call it from the JDialog constructor.

See Javadocs on setModal(boolean) .
http://java.sun.com/javase/6/docs/api/java/awt/Dialog.html#setModal(boolean)

This will force execution to block the current thread until the dialog box closes.

Alternatively you can use:

 setModalityType(Dialog.DEFAULT_MODALITY_TYPE); 

This is equivalent to setModal(true) and technically the correct way to do this.

+17
source share

See the JDialog constructor http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog,%20java.lang.String,%20boolean) . You can set the modality of this dialog. Setting modal = true pauses your application. you can also use the 'setModal' method http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Dialog.html#setModal(boolean)

+1
source share

All Articles