In JxBrowser 6 several changes to public API have been introduced. These changes may require changes to your application’s source code. This short guide shows how to change your application’s source code written with JxBrowser 5.x API to JxBrowser 6.0 API.

Creating BrowserContext

5.x

To configure BrowserContext instance in 5.x you can pass parameters directly to its constructor:

String dataDir = new File("user-data-dir-one").getAbsolutePath();
BrowserContext browserContext = new BrowserContext(dataDir);

6.0

In 6.0 parameters during BrowserContext instance construction should be provided via BrowserContextParams instance:

String dataDir = new File("user-data-dir-one").getAbsolutePath();
BrowserContextParams params = new BrowserContextParams(dataDir);
BrowserContext browserContext = new BrowserContext(params);

Creating Browser

5.x

When you create a new Browser instance, you create an instance with lightweight rendering mode. JxBrowser 5.x supports only lightweight rendering mode.

String dataDir = new File("user-data-dir-one").getAbsolutePath();
BrowserContext browserContext = new BrowserContext(dataDir);

6.0

When you create a new Browser instance, you create an instance with heavyweight rendering mode by default. To create Browser instance with lightweight rendering mode use BrowserType.LIGHTWEIGHT constructor parameter.

Browser browser = new Browser();
Browser browser = new Browser(BrowserType.HEAVYWEIGHT);
Browser browser = new Browser(BrowserType.LIGHTWEIGHT);

Configuring Browser instance with proxy settings

5.x

In 5.x each Browser instance can be configured with custom proxy settings during Browser instance construction:

HostPortPair httpServer = new HostPortPair("http-proxy-server", 80);
HostPortPair httpsServer = new HostPortPair("https-proxy-server", 80);
HostPortPair ftpServer = new HostPortPair("ftp-proxy-server", 80);
String exceptions = "<local>";
    Browser browser = new Browser(new CustomProxyConfig(httpServer,
    httpsServer, ftpServer, exceptions));

6.0

In 6.0 each Browser instance can be configured with custom proxy settings only through BrowserContext instance:

String dataDir = new File("dataDir").getAbsolutePath();
BrowserContextParams params = new BrowserContextParams(dataDir);
String proxyRules = "http=foo:80;https=foo:80;ftp=foo:80;socks=foo:80";
String exceptions = "<local>";
params.setProxyConfig(new CustomProxyConfig(proxyRules, exceptions));
Browser browser = new Browser(new BrowserContext(params));

Accessing ProxyConfig of Browser instance

5.x

ProxyConfig proxyConfig = browser.getProxyConfig();

6.0

ProxyConfig proxyConfig = browser.getContext().getProxyConfig();

Filtering keyboard events

5.x

Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
browserView.setKeyFilter(new KeyFilter<KeyEvent>() {
    public boolean filter(KeyEvent event) {
        boolean controlDown = event.isControlDown();
        boolean isVK_A = event.getKeyCode() == KeyEvent.VK_A;
        return controlDown && isVK_A;
    }
});

6.0

Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
view.setKeyEventsHandler(KeyEventsHandler.KeyEventType.ANY,
        new KeyEventsHandler<KeyEvent>() {
            public boolean handle(KeyEvent event) {
                boolean controlDown = event.isControlDown();
                boolean isVK_A = event.getKeyCode() == KeyEvent.VK_A;
                return controlDown && isVK_A;
            }
        });

Getting image of loaded HTML

5.x

Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
Image image = view.getImage();

6.0

In 6.0 obtaining image of loaded web page works only in lightweight rendering mode:

Browser browser = new Browser(BrowserType.LIGHTWEIGHT);
BrowserView view = new BrowserView(browser);
LightWeightWidget lightWeightWidget =
        (LightWeightWidget) view.getComponent(0);
Image image = lightWeightWidget.getImage();
Go Top