Search code examples
javaswingawthtmljtextpane

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


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.


Solution

  • 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.