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.4.3 API to JxBrowser 6.0 API.
(在JxBrowser 6中,对公共API进行了一些更改。这些更改可能需要更改您的应用程序的源代码。本简短指南介绍了如何将使用JxBrowser 5.4.3 API编写的应用程序源代码更改为JxBrowser 6.0 API。)


Creating BrowserContext(创建BrowserContext)

5.4.3
(5.4.3)

To configure BrowserContext instance in 5.4.3 you can pass parameters directly to its constructor:(要在5.4.3中配置BrowserContext实例,可以将参数直接传递给其构造函数:)

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

6.0(6.0)

In 6.0 parameters during BrowserContext instance construction must be provided via BrowserContextParams instance:(在6.0中,必须通过BrowserContextParams实例提供BrowserContext实例构造期间的参数:)

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

Creating Browser(创建浏览器)

5.4.3(5.4.3)

When you create a new Browser instance, you create an instance with lightweight rendering mode. JxBrowser 5.4.3 supports only lightweight rendering mode.(创建新的浏览器实例时,将创建具有轻量级渲染模式的实例。 JxBrowser 5.4.3仅支持轻量级渲染模式。)

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

6.0(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实例,请使用BrowserType.LIGHTWEIGHT构造函数参数。)

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

Configuring Browser instance with proxy settings(使用代理设置配置浏览器实例)

5.4.3(5.4.3)

In 5.4.3 each Browser instance can be configured with custom proxy settings during Browser instance construction: (在5.4.3中,可以在构造浏览器实例期间为每个浏览器实例配置自定义代理设置:)

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 (6.0)

In 6.0 each Browser instance can be configured with custom proxy settings only through BrowserContext instance:(在6.0中,只能通过BrowserContext实例为每个Browser实例配置自定义代理设置:)

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(访问浏览器实例的ProxyConfig)

5.4.3 (5.4.3)

ProxyConfig proxyConfig = browser.getProxyConfig();

 6.0 (6.0)

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

Filtering keyboard events(筛选键盘事件)

5.4.3(5.4.3)

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(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(获取已加载HTML的图像)

5.4.3(5.4.3)

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

6.0(6.0)

In 6.0 obtaining image of loaded web page works only in lightweight rendering mode:(在6.0中,获取加载的网页的图像仅在轻量级渲染模式下有效:)

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