Javafx、xdocreport和线程创建报告
我想在JavaFx中实现进度条,它将指示使用xdocreport docx或pdf文件创建报告的状态。有什么建议我怎样才能做到。举个例子?我怎么能用线来做呢 我试过这样做,但有些东西不起作用Javafx、xdocreport和线程创建报告,java,multithreading,javafx,xdocreport,Java,Multithreading,Javafx,Xdocreport,我想在JavaFx中实现进度条,它将指示使用xdocreport docx或pdf文件创建报告的状态。有什么建议我怎样才能做到。举个例子?我怎么能用线来做呢 我试过这样做,但有些东西不起作用 /** * Called when the user clicks the assign button. Generates Report about Employee * */ @FXML private void generateEmployeeReport() { Task&l
/**
* 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();
}
文件已创建,但进度栏会不断显示某些工作,并不断指示进度您没有更新进度。在您的调用中使用来更新进程updateProgress方法参数使用什么?它都在文档中,您需要查看它。有两个论点:WorkOne和totalWork。所以,如果totalWork是10,那么可以将参数传递为1、10、2、10等等。但就我而言,totalWork和WorkOne的指标是什么。我正在创建一个pdf文件。也许是文件的大小?不,在你的例子中是很复杂的,因为通常工作是分在WorkOne中的。例如,如果我们使用缓冲区编写一个文件,那么对于每个迭代,我们都可以更新进度,直到编写完整个文件。这里没有任何这样的迭代。您必须决定如何更新进度。