I have a button to print iReport but it take time to display the report so I made a loading frame class called Loading
and I am trying to call this class when I
Like all questions relating to doing long running or blocking tasks in Swing, start with Concurrency in Swing to better understand the problem you're trying to solve. Next take a look at Worker Threads and SwingWorker for the most common solution
For example:
public static class JasperReportsWorker extends SwingWorker {
@Override
protected JasperReport doInBackground() throws Exception {
JasperReport report = null;
try {
String reportquery = "Select * from invoices ";
JasperDesign jasperdesign = JRXmlLoader.load("StatementReport.jrxml");
JRDesignQuery designquery = new JRDesignQuery();
designquery.setText(reportquery);
jasperdesign.setQuery(designquery);
report = JasperCompileManager.compileReport(jasperdesign);
} finally {
try {
rs.close();
pst.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return report;
}
}
Which could then be used something like:
JasperReportsWorker worker = new JasperReportsWorker();
JDialog dialog = new JDialog();
dialog.setModal(true);
dialog.add(new JLabel("Working..."));
dialog.pack();
dialog.setLocationRelativeTo(null);
worker.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
String name = evt.getPropertyName();
JasperReportsWorker worker = (JasperReportsWorker) evt.getSource();
if ("state".equalsIgnoreCase(name)) {
switch (worker.getState()) {
case DONE:
if (dialog != null) {
dialog.setVisible(false);
}
try {
JasperReport report = worker.get();
JasperPrint jasperprint = JasperFillManager.fillReport(jasperreport, null, con);
JasperViewer.viewReport(jasperprint, false);
} catch (InterruptedException | ExecutionException ex) {
ex.printStackTrace();
}
break;
}
}
}
});
worker.execute();
dialog.setVisible(true);
The are a number of variations around the basic idea, so feel free to experiment