javafx上的模态对话框无法预测地挂起

时间:2021-03-29 17:02:23

Class extending from javafx.stage.Stage using Modality.Application_MODAL causes the application (sometimes the operating system too) to hang for an unpredictable time.

使用Modality.Application_MODAL从javafx.stage.Stage扩展的类会导致应用程序(有时也是操作系统)挂起一段不可预测的时间。

I have a class

我上课了

ModalDialog extends Stage{
    ModalDialog(){
        super(StageStyle.TRANSPARENT);
        initModality(Modality.APPLICATION_MODAL);
    }
}

On calling showAndWait() of an instance of the above class the app hangs for an unpredictible time. This happends on Ubuntu Linux 13.10. The jconsole shows stacktrace of the JavaFX-ApplicationThread is:

在调用上述类的实例的showAndWait()时,应用程序会挂起一段不可预测的时间。这发生在Ubuntu Linux 13.10上。 jconsole显示了JavaFX-ApplicationThread的堆栈跟踪:

com.sun.glass.ui.gtk.GtkApplication.enterNestedEventLoopImpl(Native Method)
com.sun.glass.ui.gtk.GtkApplication._enterNestedEventLoop(GtkApplication.java:144)
com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:384)
com.sun.glass.ui.EventLoop.enter(EventLoop.java:83)
com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:523)
javafx.stage.Stage.showAndWait(Stage.java:398)

Is there a known explanation for this behaviour?

这种行为有没有已知的解释?

1 个解决方案

#1


1  

Its best to set an intiOwner for the dialog for the system to know the parent frame of your dialog. This enables the dialog to be modal to the parent frame rather than just being modal to nothing. This can take care of your problem i think.

最好为对话框设置一个intiOwner,以便系统知道对话框的父框架。这使得对话框可以模态到父框架,而不仅仅是模态到任何东西。我认为这可以解决你的问题。

ModalDialog extends Stage{
     ModalDialog(Stage parentStage){
       super(StageStyle.Transparent);
       initOwner(parentStage);
       initModality(Modality.Application_Modal);
   }

This should do

这应该做

#1


1  

Its best to set an intiOwner for the dialog for the system to know the parent frame of your dialog. This enables the dialog to be modal to the parent frame rather than just being modal to nothing. This can take care of your problem i think.

最好为对话框设置一个intiOwner,以便系统知道对话框的父框架。这使得对话框可以模态到父框架,而不仅仅是模态到任何东西。我认为这可以解决你的问题。

ModalDialog extends Stage{
     ModalDialog(Stage parentStage){
       super(StageStyle.Transparent);
       initOwner(parentStage);
       initModality(Modality.Application_Modal);
   }

This should do

这应该做