Best component in awt/swings to display the webpage and access it

这一生的挚爱 提交于 2020-01-06 16:23:35

问题


Which is the best component in awt/Swings to display the webpage and access the webpage in that component without any issues like (functioning of javascript, images in the page should display good, as viewing the page on browser and support as browser with all functionalities) here there is a tutorial about it displaying webpage but it says,we cannt assure JEditotPane will provide as browser.

You can see in the last paragraph of that tutorial. I need to implement that, webpage to be displayed in awt/swings. I tried the example in that link, but got message: "Please enable javascript to display".

So can anyone please guide me, regarding the best approach to display webpage on swings/awt or any alternative for that.

Update :

I have downloaded the jars for Jbrowser and tried one example which was there in Jbrowser site. But getting below exception.

        import java.awt.Canvas;  
    import java.awt.Dimension;  
    import java.awt.Toolkit;  
    import javax.swing.JFrame;    
    import ru.atomation.jbrowser.impl.JBrowserComponent;  
    import ru.atomation.jbrowser.impl.JBrowserBuilder;  
    import ru.atomation.jbrowser.impl.JBrowserCanvas;  
    import ru.atomation.jbrowser.impl.JComponentFactory;  
    import ru.atomation.jbrowser.interfaces.BrowserManager;
public class GettingStartedSnippet {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize((int) (screenSize.getWidth() * 0.75f),
                (int) (screenSize.getHeight() * 0.75f));
        frame.setLocationRelativeTo(null);
        BrowserManager browserManager =   new JBrowserBuilder().buildBrowserManager();
        JComponentFactory<Canvas> canvasFactory = browserManager.getComponentFactory(JBrowserCanvas.class);
        JBrowserComponent<?> browser = canvasFactory.createBrowser();                    
        frame.getContentPane().add(browser.getComponent());          
        frame.setVisible(true);            
        browser.setUrl("http://code.google.com/p/jbrowser/");  

    }

}

This is the link where i find that example GettingStartedSnippet

Exception :

Apr 18, 2012 3:42:11 PM ru.atomation.jbrowser.impl.JBrowserBuilder getXulRunnerPath
INFO: Unpacking mozilla to: D:\WorkSpaces\example\example\jbrowser
Apr 18, 2012 3:42:11 PM ru.atomation.xulnative.XulExtractor extract
SEVERE: Xulrunner archive not found in jar
Apr 18, 2012 3:42:11 PM ru.atomation.jbrowser.impl.JBrowserManager initialize
SEVERE: invalid current xulrunner location D:\WorkSpaces\example\example\jbrowser\xulrunner\xulrunner
Apr 18, 2012 3:42:11 PM ru.atomation.jbrowser.impl.JBrowserManager initialize
INFO: Continuing to search for other xulrunners
Apr 18, 2012 3:42:11 PM ru.atomation.jbrowser.impl.JBrowserManager initialize
SEVERE: failed to initialize mozilla
Throwable occurred: java.io.IOException: Unable to resolve XULRunner home location
    at ru.atomation.jbrowser.impl.JBrowserManager.initialize(JBrowserManager.java:118)
    at ru.atomation.jbrowser.impl.JBrowserManager.<init>(JBrowserManager.java:67)
    at ru.atomation.jbrowser.impl.JBrowserBuilder.buildBrowserManager(JBrowserBuilder.java:127)
    at GettingStartedSnippet.main(GettingStartedSnippet.java:23)

I browsered to find the solution, i could not get apt solution for the issue. Please can anyone provide me solution.


回答1:


..or any alternative for that.

Use an actual embedded browser.

E.G.

  • JDIC: Embedding a Web browser in Java
  • jbrowser - Java browser based on Mozilla Embedded API



回答2:


Jbrowser is used xullrunner form mozilla project, so jbrowser is wrapper for firefox browser.

For my issue i used NativeSwing library , it is best component i feel.with this i implemented integrating webpage which is non html page in to Swing application.




回答3:


1.First download jbrowser-linux-demo-with-sources.tar. 2.Then Create java application called "JbrowserDemo". 3.Copy Xulrunner folder which is in jbrowser-linux-demo-with-sources. 4.Paste in your application folder(JbrowserDemo). 5.Then run your application "GettingStartedSnippet"



来源:https://stackoverflow.com/questions/10205917/best-component-in-awt-swings-to-display-the-webpage-and-access-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!