在jxbrowser中弹出关闭事件

时间:2016-02-15 14:02:02

标签: popupwindow jxbrowser

我为jxbrowser 6.0实现了一个弹出处理程序。

popup是否有办法向主浏览器发送(事件)它(弹出窗口)已关闭?

主浏览器必须暂停此活动,直到打开的弹出窗口关闭。

2 个答案:

答案 0 :(得分:0)

要了解弹出窗口何时关闭,请使用以下方法:

browser.setPopupHandler(new PopupHandler() {
    public PopupContainer handlePopup(PopupParams params) {
        return new PopupContainer() {
            public void insertBrowser(final Browser browser, final Rectangle initialBounds) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        BrowserView popupView = new BrowserView(browser);
                        popupView.setPreferredSize(initialBounds.getSize());

                        final JFrame popupFrame = new JFrame("Popup");
                        popupFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        popupFrame.add(popupView, BorderLayout.CENTER);
                        popupFrame.pack();
                        popupFrame.setLocation(initialBounds.getLocation());
                        popupFrame.setVisible(true);
                        popupFrame.addWindowListener(new WindowAdapter() {
                            @Override
                            public void windowClosing(WindowEvent e) {
                                browser.dispose();
                            }
                        });

                        browser.addDisposeListener(new DisposeListener<Browser>() {
                            public void onDisposed(DisposeEvent<Browser> event) {
                                popupFrame.setVisible(false);
                                // Notify parent that popup has been closed.
                            }
                        });
                    }
                });
            }
        };
    }
});

答案 1 :(得分:0)

我已经找到了一个带有布尔变量的运行解决方案,但我想要一个更优雅的解决方案。

            browser.addDisposeListener(new DisposeListener() {
                public void onDisposed(DisposeEvent event) {
                    finestraAComparsa.setVisible(false);
                    Automazione.finestraAComparsaChiusa = true;//
                    // Notify parent that popup has been closed.
                }
            });

在主浏览器类文件中:

                try {
                    while (!finestraAComparsaChiusa) {
                        Thread.sleep(1000);
                    }
                    finestraAComparsaChiusa = false;
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }