This code is for progress bar. i'm using this progress bar for a background process but the problem is the progress bar is only visible after the background task completed !!
public class ProgBar {
public void porgressBarTest(){
ProgressBar progressBar = new ProgressBar();
progressBar.setProgress(0);
progressBar.setMinWidth(400);
VBox updatePane = new VBox();
updatePane.setPadding(new Insets(30));
updatePane.setSpacing(5.0d);
updatePane.getChildren().addAll(progressBar);
Stage taskUpdateStage = new Stage(StageStyle.UTILITY);
taskUpdateStage.setScene(new Scene(updatePane));
taskUpdateStage.show();
Task<Void> task = new Task<Void>() {
public Void call() throws Exception {
int max = 200;
for (int i = 1; i <= max; i++) {
updateProgress(i, max);
Thread.sleep(100);
}
System.out.println("about to close");
return null;
}
};
progressBar.progressProperty().bind(task.progressProperty());
new Thread(task).start();
}
}
i want to use progress bar for this method!
public void exportFile(String fileFormat) throws EngineException {
String output = *************;
String reportDesignFilePath = ********************;
// Save Report In Particular Format
try {
EngineConfig configure = new EngineConfig();
Platform.startup(configure);
IReportEngineFactory reportEngineFactory=(IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
IReportEngine engine = reportEngineFactory.createReportEngine(configure);
engine.changeLogLevel(Level.WARNING);
IReportRunnable runnable = engine.openReportDesign(reportDesignFilePath);
IRunAndRenderTask task = engine.createRunAndRenderTask(runnable);
IRenderOption option = new PDFRenderOption();
option.setOutputFormat(fileFormat);
option.setOutputFileName(output+fileFormat);
task.setRenderOption(option);
task.run();
task.close();
}
catch(Exception e) { e.printStackTrace(); }
// Open Created File
File file = new File(output+fileFormat);
if (file.exists()) {
if (Desktop.isDesktopSupported()) {
try {
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
}
catch(IOException e) {
e.printStackTrace();
}
}
}
}