New version is available You are viewing the documentation for JxBrowser 6 which is not supported since December 2019. Go to the current documentation.
List icon 目录

This guide describes how to manage file downloads, track a download progress, get a notification when the download has been completed, etc.

Overview

JxBrowser provides API that allows handling all the file downloads. Using this API you can control what files should be downloaded, provide path to the destination directory where file must be saved and track download progress.

Allow Download

You can register your own implementation of the DownloadHandler interface to handle file downloads in your own way. The following sample demonstrates how to do this:

browser.setDownloadHandler(new DownloadHandler() {
    public boolean allowDownload(DownloadItem download) {
        download.addDownloadListener(new DownloadListener() {
            public void onDownloadUpdated(DownloadEvent event) {
                DownloadItem download = event.getDownloadItem();
                if (download.isCompleted()) {
                    System.out.println("Download is completed!");
                }
            }
        });
        System.out.println("Dest file: " + download.getDestinationFile().getAbsolutePath());
        return true;
    }
});

The DownloadItem class provides methods for pausing and canceling download process. See its corresponding methods.

Go Top