怎么能理解DJ原生swing的jwebbrowser已经完全加载了网页



我想在DJ本机swing jwebbrowser中执行javascript代码,但我应该等待页面加载,我如何为它设置侦听器?我尝试以下,但加载后总是运行脚本,它也操作晚!

webBrowser.addWebBrowserListener(new WebBrowserListener(){
        @Override
        public void commandReceived(WebBrowserCommandEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void loadingProgressChanged(WebBrowserEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void locationChanged(WebBrowserNavigationEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void locationChanging(WebBrowserNavigationEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void statusChanged(WebBrowserEvent arg0) {
            // TODO Auto-generated method stub
            if(webBrowser.getLoadingProgress() == 100)
                webBrowser.executeJavascript("some js code");");
        }
        @Override
        public void titleChanged(WebBrowserEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void windowClosing(WebBrowserEvent arg0) {
            // TODO Auto-generated method stub
            frame.dispose();
        }
        @Override
        public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
            // TODO Auto-generated method stub
        }
        @Override
        public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
            // TODO Auto-generated method stub
        }
    });

我该怎么办?

我应该重写loadingProgressChanged(WebBrowserEvent arg0)而不是statusChanged(WebBrowserEvent arg0)

@Override public void loadingProgressChanged(WebBrowserEvent arg0) { // TODO Auto-generated method stub if(webBrowser.getLoadingProgress() == 100) webBrowser.executeJavascript("some js code"); }

,但仍然需要时间来加载我的html!

相关内容

  • 没有找到相关文章