等待函数返回,直到JFrame在JavaFX线程中关闭

等待函数返回,直到JFrame在JavaFX线程中关闭,java,javafx,event-handling,jdialog,Java,Javafx,Event Handling,Jdialog,下面的函数将JavaFX面板放入SwingJDialog中,向JFX面板添加webview,并在其中呈现HTML报告 我试图实现的是使displayHTMLOutput函数仅在HTML已显示且JDialog已关闭时返回。由于内容是在JavaFX线程中呈现的,因此我无法捕捉到关闭对话框。如何做到这一点 /* Displays a given OutputTable object in a dialog */ public static void displayHTMLOutput(OutputTa

下面的函数将JavaFX面板放入SwingJDialog中,向JFX面板添加webview,并在其中呈现HTML报告

我试图实现的是使displayHTMLOutput函数仅在HTML已显示且JDialog已关闭时返回。由于内容是在JavaFX线程中呈现的,因此我无法捕捉到关闭对话框。如何做到这一点

/* Displays a given OutputTable object in a dialog */
public static void displayHTMLOutput(OutputTable table) {

    /* Create modal dialog and JFXPanel */
    JDialog dialog = new JDialog((Window) null);
    JFXPanel jfxPanel = new JFXPanel();

    /* Add JFXPanel to dialog */
    dialog.add(jfxPanel);

    /* Configure the dialog */

    dialog.setSize(1200, 800);
    dialog.setLocationRelativeTo(null);

    /* Maps escape key to closing the dialog */
    key(dialog);

    /* sets an icon for the dialog */
    ImageIcon img = new ImageIcon("icons/report.png");
    dialog.setIconImage(img.getImage());

    /* Show the dialog */
    dialog.setVisible(true);

    /* Runs ons the JavaFX Application Thread at a later time */
    Platform.runLater(() -> {

        /* Create webview and bind to scene */
        WebView webView = new WebView();        
        jfxPanel.setScene(new Scene(webView));

        /* Load the html in a webview */
        webView.getEngine().loadContent(DisplayHtml.getOutputHTMLOutputTable("template.html", table));      

        /* Do some actions on the dialog */
        dialog.setAlwaysOnTop(true);
        dialog.setModal(true);
        dialog.requestFocus();

    });

}

多亏了@Slaw的引用帖子,我才能够重写代码以获得所需的结果。事实证明,只有在将webview代码放在JavaFX线程上之后,该窗口才可见

/* Displays a given OutputTable object in a dialog */
public static void displayHTMLOutput(OutputTable table) {

    /* Create modal dialog and JFXPanel */
    JDialog dialog = new JDialog((Window) null);
    JFXPanel jfxPanel = new JFXPanel();

    /* Add JFXPanel to dialog */
    dialog.add(jfxPanel);

    /* Configure the dialog */

    dialog.setModalityType(ModalityType.APPLICATION_MODAL);
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.setSize(1200, 800);

    /* Maps escape key to closing the dialog */
    key(dialog);

    /* sets an icon for the dialog */
    ImageIcon img = new ImageIcon("icons/report.png");
    dialog.setIconImage(img.getImage());

    /* Runs ons the JavaFX Application Thread at a later time */
    Platform.runLater(() -> {

        /* Create webview and bind to scene */
        WebView webView = new WebView();        
        jfxPanel.setScene(new Scene(webView));

        /* Load the html in a webview */
        webView.getEngine().loadContent(DisplayHtml.getOutputHTMLOutputTable("template.html", table));      

    });

    /* Do some actions on the dialog */
    dialog.setAlwaysOnTop(true);
    dialog.requestFocus();
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

    /* Test is now only printed to console when the dialog is closed */
    System.out.println("test");     
}

看一看。如果我正确理解了答案(以及您的问题),那么在关闭
JDialog
之前停止执行的方法就是将其设置为模态。谢谢@Slaw,您引用的帖子使我能够更改代码以使其正常工作!