public void viewReport(String text, JTabbedPane pnl, int year) { sid = Integer.parseInt(text); if (text.equals("")) { JOptionPane.showMessageDialog(repstu, "Type the Student Id"); } else { String rep_path = System.getProperty("user.dir") + "/reports/payment_stu.jrxml"; Map<String, Object> params = new HashMap<String, Object>(); params.put("sid", sid); params.put("year", "" + year); params.put("name", this.getName()); params.put("datetime", this.getDateTime()); try { JasperReport jreport = JasperCompileManager.compileReport(rep_path); JasperPrint jprint = JasperFillManager.fillReport(jreport, params, DB.getmyCon()); JRViewer jview = new JRViewer(jprint); pnl.removeAll(); pnl.add("Report", jview); jview.setZoomRatio((float) 0.9); } catch (Exception ex) { System.out.println("ERROR:" + ex); } } }
public void abrirRelatorio(ActionEvent evt) { try { String arquivo = "condominio/core/administrativo/relatorios/Blank_A4.jasper"; // arquivo de relatorio java.io.InputStream file = getClass().getClassLoader().getResourceAsStream(arquivo); // carrego o arquivo List<TIPO_MORADOR> allTipoMorador = pCrud.getAllTipoMorador(); JRBeanArrayDataSource dataSource = new JRBeanArrayDataSource( allTipoMorador.toArray( new TIPO_MORADOR [allTipoMorador .size()])); // aqui eu crio um datasource usando a propria jtable Map parametros = new HashMap(); // apenas crio um map, mas nem passo parametro nem nada, os parametros sao // as colunas da jtable JasperPrint printer = JasperFillManager.fillReport(file, parametros, dataSource); JRViewer view = new JRViewer(printer); view.setVisible(true); SwingNode panel = new SwingNode(); panel.prefHeight(500); panel.prefWidth(500); panel.setContent(view); relat.getChildren().add(panel); } catch (JRException e) { e.printStackTrace(); } }