3

I'm currently playing around with the Evaluation License for JxBrowser 6.2.

I'm creating the BrowserView as follows:

Browser browser = new Browser(BrowserType.HEAVYWEIGHT);
BrowserView browser_view = new BrowserView(browser);

I'm attaching the BrowserView component as follows:

stage.setScene(new Scene(browser_view));

If the Browser is configured to operate in LIGHTWEIGHT mode, I'm able to execute:

browser_view.getBrowser().dispose();
Platform.exit();

However, if the Browser is configured to operate in HEAVYWEIGHT mode, then the application hangs when executing:

browser_view.getBrowser().dispose();

I can see in the logs that the Dispose message was written, but it appears as though the JxBrowser Chromium processes never receive/process the message.

Any ideas?

blf
  • 85
  • 8

4 Answers4

2

As answered before me the solution to this is to dispose the browser after the stage has been hidden (closed).
A good approach would be to put those commands on the stop() method of JavaFX Application.
So that either way you close the window (by clicking the close button or programmatically by calling Platform.exit()), the browser will dispose (and the whole application will finish and exit).

Something like that:

@Override
public void stop() throws Exception {
    stage.hide();
    browser.dispose();
}
LionGod8
  • 368
  • 2
  • 9
1

As a reference, I used configuration described here link (Section: 9. Pop-up Windows).

Platform.runLater(() -> {
    browser.dispose();
});

Platform.runLater(() -> {
    stage.close();
});
Bosko Popovic
  • 281
  • 1
  • 4
  • 4
0

It looks like you need to ensure that the stage has been closed before calling dispose.

stage.close();
browser_view.getBrowser().dispose();
Platform.exit();
blf
  • 85
  • 8
  • If you use `stage.setOnHidden()` instead of `stage.setOnCloseRequest()`, you will be guaranteed the stage is already closed. – James_D Mar 05 '16 at 23:31
  • Hm... I just gave this a shot. Although the Java Documentation says that close() is equivalent to hide(), and that hide() merely sets the window visibility to false, close() appears to be doing more. The browser still hangs until the stage is explicitly closed. – blf Mar 06 '16 at 00:34
  • But the `setOnHidden` handler, unlike the `setOnCloseRequest` handler you said you are using, isn't called until the stage is closed. – James_D Mar 06 '16 at 00:51
  • You can even look at the [source code](http://hg.openjdk.java.net/openjfx/8/master/rt/file/f89b7dc932af/modules/graphics/src/main/java/javafx/stage/Stage.java) if you like, and see that `close()` simply calls `hide()`, so they are completely equivalent. – James_D Mar 06 '16 at 00:58
  • Hm... Perhaps close()/hide() are doing more than is normally done when clicking the close button (big red X on Windows). I did test calling hide() and it works the same as calling close(). To be sure, calling close() is a workable solution. It's just more than I normally need to do when handling the window close request. – blf Mar 06 '16 at 01:28
  • Note than clicking the big red X does in fact hide the window. But without explicitly calling close(), the browser refuses to dispose, leaving the process running. – blf Mar 06 '16 at 01:29
0

Please try calling this code asynchronously. Maybe it's just a deadlock:

Platform.runLater(new Runnable() {
    @Override
    public void run() {
        browser_view.getBrowser().dispose();
        Platform.exit();
    }
});
Vladimir
  • 1
  • 1
  • 23
  • 30