Reputation: 838
I am calling this function from a report preview form of a panel.
demo : Main Panel - [which calls] - ReportSelectionDialog(Frame) - [which opens] Report(Frame)
the problem is that when I open the report directly from the MainPanel
demo : Main Panel - - Report(Frame)
the JasperFillManager only takes like a second to fill the report but when I do the first demo, it took JasperFillManager 20-30 seconds to fill the report. I checked on the parameters required (connection, parameter map) and they were loaded instantly upon opening ReportSelectionDialog. I need the ReportSelectionDialog but I dont want to wait so long just to open a report. Please help. Here is my code to load the report. Is there another way to fill the reports. And also is there a way to just load the .jasper file instead of compiling the report everytime?
private void openReport(){
String reportFile = getFileName(reportList.getSelectedValue().toString());
FileInputStream fs = null;
try {
fs = new FileInputStream(reportPath+reportFile);
JasperDesign jasperDesign = JRXmlLoader.load(fs);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
javax.swing.JFrame jframe = new javax.swing.JFrame();
jframe.setIconImage(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/timsoftware/images/timlogo.png")));
jframe.getContentPane().add(new JRViewer(jasperPrint));
jframe.pack();
jframe.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
jframe.setVisible(true);
} catch (FileNotFoundException | JRException | HeadlessException e) {
clsErrorHandler.printError(e.toString(), panelName, "PrintRecord");
} finally {
try {
fs.close();
} catch (IOException ex) {
Logger.getLogger(ReportPreviewForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
this.dispose();
}
Upvotes: 0
Views: 3474
Reputation: 6969
JasperDesign jasperDesign = JRXmlLoader.load(fs);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Move those lines out of the method and somewhere in your initialization sequence. May be the constructor? And it should do the trick. Problem is you are compiling the report over and over again in the method, which is not necessary. If you do it once to initialize jasperReport
it's enough.
Upvotes: 1