Search code examples
javajxbrowser

JxBrowser BrowserFactory missing from driver file


I am trying to install JxBrowser (following this tutorial), and after installing the JxBrowser driver:

enter image description here

I tried to compile, and noticed the necessary import BrowserFactory was missing:

enter image description here

And, rummaging through the class files in the driver, sure enough there's no BrowserFactory available:

enter image description here

Am I doing something wrong? Is there a necessary component to JxBrowser that I am missing? Does the new version of the driver not include a BrowserFactory class?


Solution

  • The sample at https://dzone.com/articles/google-maps-java-swing is based on JxBrowser 4.x API. You use JxBrowser 5.x API which is a little bit different. Now, with 5.x API, to create Browser instance you don't need to use BrowserFactory class.

    The following sample demonstrates how to write same code with JxBrowser 5.x API:

    import com.teamdev.jxbrowser.chromium.Browser;
    import com.teamdev.jxbrowser.chromium.swing.BrowserView;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     * This sample demonstrates how to load a web page with Google Maps
     * and control it using JxBrowser API.
     */
    public class GoogleMapsSample {
        public static void main(String[] args) {
            Browser browser = new Browser();
            BrowserView view = new BrowserView(browser);
    
            JFrame frame = new JFrame("JxBrowser Google Maps");
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.add(view, BorderLayout.CENTER);
            frame.setSize(700, 500);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    
            browser.loadURL("http://maps.google.com");
        }
    }