Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here and here.(注意:本文中的建议仅适用于JxBrowser6。请在此处和此处参阅有关JxBrowser 7的相应文章。)

When you don't need to use a Browser instance you must dispose it using the Browser.dispose() method.(当您不需要使用Browser实例时,必须使用Browser.dispose()方法把它处决。)

For example: (例如:)


Accessing disposed instance(访问已销毁的实例)

Once you dispose a Browser instance, you cannot use it anymore. If you try to access already disposed Browser instance the IllegalStateException exception will be thrown. For example: (处置浏览器实例后,将无法再使用它。如果尝试访问已处理的浏览器实例,则将抛出IllegalStateException异常。例如:)

browser.getDocument(); // IllegalStateException will be thrown

To check if the Browser instance is disposed or not, you can use the Browser.isDisposed() method.(要检查是否销毁了Browser实例,可以使用Browser.isDisposed()方法。)

Dispose events(销毁事件)

Each Browser instance can be also disposed from JavaScript via the window.close() function. In this case you might be interested in receiving notification when a Browser instance is disposed. To get such notifications, you can use DisposeListener. For example: (浏览器实例也可以通过window.close()函数从JavaScript进行销毁。在这种情况下,您需要在销毁浏览器实例时收到通知。要获取此类通知,可以使用DisposeListener。例如:)

browser.addDisposeListener(new DisposeListener<Browser>() {
    public void onDisposed(DisposeEvent<Browser> event) {
        // B<span class="fr-marker" data-id="0" data-type="false" style="display: none; line-height: 0;"></span><span class="fr-marker" data-id="0" data-type="true" style="display: none; line-height: 0;"></span>rowser is disposed

When you dispose a Browser instance manually via the Browser.dispose() method, the Dispose event will also be fired.(当您通过Browser.dispose()方法手动释放Browser实例时,也会触发Dispose事件。)