0

我想在 JavaFx 中实现进度条,这将指示使用 xdocreport(docx 或 pdf 文件)创建报告的状态。任何建议我怎么能做到这一点。一些例子?我该如何使用 Thread 呢?

我试过这样,但有些东西不起作用。

 /**
 * Called when the user clicks the assign button. Generates Report about Employee
 *  
 */
@FXML
private void generateEmployeeReport() {


    Task<Void> task = new Task<Void>() {
        @Override public Void call() {


             try {
                 // 1) Load Docx file by filling Velocity template engine and cache
                 // it to the registry
                 InputStream in = RootController.class
                                 .getResourceAsStream("ReportEmployeeTemplate.docx");
                 IXDocReport report = XDocReportRegistry.getRegistry().loadReport(
                                 in, TemplateEngineKind.Velocity);

                 // 2) Create context Java model
                 IContext context = report.createContext();
                 ReportEmployee project = new ReportEmployee("Majmun");
                 context.put("ReportEmployee", project);

                 // 3) Generate report by merging Java model with the Docx
                 OutputStream out = new FileOutputStream(new File(
                                 "bzzer.pdf"));


                 // report.process(context, out);
                 Options options = Options.getTo(ConverterTypeTo.PDF).via(
                                 ConverterTypeVia.XWPF);
                 report.convert(context, options, out);


         } catch (IOException e) {
                 e.printStackTrace();
         } catch (XDocReportException e) {
                 e.printStackTrace();
         }  



            return null;
        }
    };



    progresBarOne.progressProperty().bind(task.progressProperty());

    Thread th = new Thread(task);
    th.setDaemon(true);
    th.start();

}

文件已创建,但进度条一直显示一些工作(保持“指示”进度)

4

0 回答 0