Search code examples
javadownloadjxbrowser

How do you download a file using the jxbrowser library?


I'm using the jxbrowser library and I have a download link. For some reason there is no download shown.

        browser.setDownloadHandler(new DownloadHandler() {
            public boolean allowDownload(DownloadItem download) {
                download.addDownloadListener(new DownloadListener() {
                    public void onDownloadUpdated(DownloadEvent event) {
                        DownloadItem download = event.getDownloadItem();
                        download.setDestinationFile(new File("C:/Users/"
                                + System.getProperty("user.name")
                                + "/Desktop/" + title));
                    }
                });

                return true;
            }
        });

        browser.loadURL(downloadURL);

Solution

  • I'm guessing here, but if you compare your code to the sample here:

    it looks like you are setting the destination for the download after the download has completed. Try setting it in the download handler rather than the download event listener.