如何在JDialog打开时暂停执行

时间:2022-04-29 11:17:15

How can I make my application pause when I open custom JDialog and after the dialog is closed to make continue again.

当我打开自定义JDialog并关闭对话框以再次继续时,如何使我的应用程序暂停。

2 个解决方案

#1


Simply use:

setModal(true);

I usually call it from within the constructor of the JDialog.

我通常在JDialog的构造函数中调用它。

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

请参阅setModal上的Javadoc(布尔值)。 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.

它等同于setModal(true),在技术上是正确的方法。

#2


See the constructor of JDialog 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 will pause your application. you can also use the method 'setModal' http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Dialog.html#setModal(boolean)

请参阅JDialog的构造函数http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog,%20java.lang.String,%20boolean )。您可以设置此对话框的模态。设置modal = true将暂停您的应用程序。你也可以使用方法'setModal'http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Dialog.html#setModal(boolean)

#1


Simply use:

setModal(true);

I usually call it from within the constructor of the JDialog.

我通常在JDialog的构造函数中调用它。

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

请参阅setModal上的Javadoc(布尔值)。 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.

它等同于setModal(true),在技术上是正确的方法。

#2


See the constructor of JDialog 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 will pause your application. you can also use the method 'setModal' http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Dialog.html#setModal(boolean)

请参阅JDialog的构造函数http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JDialog.html#JDialog(java.awt.Dialog,%20java.lang.String,%20boolean )。您可以设置此对话框的模态。设置modal = true将暂停您的应用程序。你也可以使用方法'setModal'http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Dialog.html#setModal(boolean)