How to show a progress bar while downloading in javafx

I am building a desktop app using javafx, I am downloading a file around 500 MB using ftp. I need to show the progress bar with % while downloading is in progress. I also need to give a option to cancel a ongoing downloading process.

This is my code to download file.

        try {
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            success = ftpClient.changeWorkingDirectory(PATH + preset + "/" +  file_to_download + offset);
            System.out.println("Download Path:-" + PATH + preset + "/" +  file_to_download + offset);
            if (!success) {
                System.out.println("Could not changed the directory to RIBS");
                return;
            } else {
                System.out.println("Directory changed to RIBS");
            }
            FTPFile[] files = ftpClient.listFiles();
            for (FTPFile file : files) {
                if (file.getName().contains(".zip")) {
                    dfile = file.getName();
                }

            }
            DirectoryChooser dirChooser = new DirectoryChooser();
            File chosenDir = dirChooser.showDialog(tableView.getScene().getWindow());
            System.out.println(chosenDir.getAbsolutePath());
            OutputStream output;
            output = new FileOutputStream(chosenDir.getAbsolutePath() + "/" + dfile);
            int timeOut = 500;
            ftpClient.setConnectTimeout(timeOut);
            if (ftpClient.retrieveFile(dfile, output) == true) {
                downloadButton.setDisable(true);
            }
            output.close();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


ANSWERS:


You should make yourself familiar with Concurrency in JavaFX.

And you can find several examples about what you need on the web, e. g. ProgressBar and Background Processes.



 MORE:


 ? JavaFX Change text under Progress Indicator (default: Done)
 ? JavaFX Change text under Progress Indicator (default: Done)
 ? JavaFX Change text under Progress Indicator (default: Done)
 ? Change JavaFX progress bar style
 ? Set default skin in JavaFX with ComboBox
 ? Remove rectangle from Progress Indicator
 ? Add progress bar in JavaFX table pagination
 ? JavaFX progress bar show file upload status
 ? How to configure Progress Bar and Progress Indicator of javaFx?
 ? How to configure Progress Bar and Progress Indicator of javaFx?