Display 'Loading' frame until the background process finish

前端 未结 2 676
星月不相逢
星月不相逢 2021-01-17 01:11

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

2条回答
  •  隐瞒了意图╮
    2021-01-17 01:48

    Create New Undecorated frame with loading giffy or loading name.as LoadingScreen.

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                        
                LoadingScreen ls=new LoadingScreen();
         ls.setVisible(true);// show frame before trying to connect to database and load report
        try {
            String reportquery = "Select * from invoices ";
            JasperDesign jasperdesign = JRXmlLoader.load("StatementReport.jrxml");
            JRDesignQuery designquery = new JRDesignQuery();
            designquery.setText(reportquery);
            jasperdesign.setQuery(designquery);
            JasperReport jasperreport = JasperCompileManager.compileReport(jasperdesign);
            JasperPrint jasperprint = JasperFillManager.fillReport(jasperreport, null, con);
         ls.dispose();
            JasperViewer.viewReport(jasperprint, false);
    
        } catch (JRException e) {
            JOptionPane.showMessageDialog(this, e);
    
        } finally {
            try {
                rs.close();
                pst.close();
    
            } catch (SQLException ex) {
                Logger.getLogger(showAllInvoices.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }  
    

    I hope this will run

提交回复
热议问题