Pinkie Swirl
Pinkie Swirl

Reputation: 2415

Disposing javaFX webengine in JFrame

I have a web browser in my JFrame and i think I can't get it to dispose it on exiting the application.

Here is my code that tries to accomplish that:

Platform.runLater(new Runnable() {
    @Override
    public void run() {
        webBrowserEngine.getLoadWorker().cancel();
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                Platform.exit();
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        getMainFrame().dispose(); // Is set to dispose on close
                        // SwingUtilities.invokeLater(new Runnable() {
                            // @Override
                            // public void run() {
                                // System.exit(0);
                            // }
                        // });
                    }
                });
            }
        });
    }
});

The window closes, but the java process stays and this line returns always false:

webBrowserEngine.getLoadWorker().cancel();

Upvotes: 2

Views: 805

Answers (1)

EverNight
EverNight

Reputation: 1064

Platform.exit();

Forces the FXApplicationThread to terminate. Everything associated with it is eventually finalized. You can test this by extending and overwriting the WebEngine class to handle something differently upon finalize() triggers.

Also, there exist implemetnations for self-disposers related to url processing routines within the WebEngine itself.

Additinoally, WebEngine handles some URLLoaders for resource processing. These are a bit weird to wipe since they're in a DLL... so native.

Screwing around with this lead meto a bunch of MemoryAccessViolation exceptions that required logical work-arounds.

Upvotes: 1

Related Questions