Bem vou passar o que eu fiz aki ve se vc entendi ai
essa classe é para mostar o relatorio na sua aplicação
/**
* @author Andre Heidi Moriya
*/
public class Relatorios implements IReport {
private JInternalFrame i;
JRViewer viewer;
public JasperPrint createReport(String relatorio, Integer codigo) {
JasperPrint relatorios = null;
try {
Connection con = Conexao.abrirConexao();
HashMap map = new HashMap();
map.put("Codigo", codigo);
String arq = System.getProperty("user.dir") + "/relatorios/" + relatorio + ".jasper";
relatorios = JasperFillManager.fillReport(arq, map, con);
if (viewer == null) {
viewer = new JRViewer(relatorios);
dialogReportViewer(viewer, relatorio);
}
} catch (JRException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
return relatorios;
}
/**
* Metodo para geraçao de relatorio em arquivos PDF diretamente
*/
@Override
@Deprecated
@SuppressWarnings("Metodo nao funciona corretamente")
public JasperPrint createReport(String relatorio, String jrprint, String PDF) {
JasperPrint relatorios = null;
try {
Connection con = Conexao.abrirConexao();
HashMap map = new HashMap();
String arq = System.getProperty("user.dir") + "/relatorios/" + relatorio;
String arqjrprint = System.getProperty("user.dir") + "/relatorios/" + jrprint;
String pdf = System.getProperty("user.dir") + "/relatorios/" + PDF;
JasperFillManager.fillReportToFile(arq, map, con);
JasperExportManager.exportReportToPdfFile(arqjrprint);
JasperViewer.viewReport(pdf, false);
} catch (JRException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
return relatorios;
}
/**
* Metodo para criaçao do relatorio
*/
@Override
public JasperPrint createReport(String relatorio) {
JasperPrint relatorios = null;
JRViewer viewer = null;
int codigo = 0;
try {
Connection con = Conexao.abrirConexao();
HashMap map = new HashMap();
map.put("Código", codigo);
String arq = System.getProperty("user.dir") + "/relatorios/" + relatorio + ".jasper";
relatorios = JasperFillManager.fillReport(arq, map, con);
if (viewer == null) {
viewer = new JRViewer(relatorios);
dialogReportViewer(viewer, relatorio);
}
} catch (JRException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
return relatorios;
}
/**
* Metodo para abrir o relatorio dentro de um JDialog
* @see JDialog
*/
protected void dialogReportViewer(JRViewer view, String titulo) {
JDialog dialog = new JDialog();
dialog.setModal(true);
dialog.setTitle(titulo);
dialog.setSize(900, 580);
dialog.setLayout(new BorderLayout());
dialog.add(view);
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
/**
* Metodo para abrir o relatorio dentro de um JInternalFrame
* @see JInternalFrame
*/
protected void internalReportViewer(JRViewer view, String titulo){
if(i == null || !i.isVisible()){
i = new JInternalFrame(titulo, true, true, true, true);
i.setSize(900, 580);
i.setLayout(new BorderLayout());
i.add(view);
i.setVisible(true);
FormMenu.getDesktopPane(i);
Controles.centerInternal(FormMenu.getDesktopPane(), i);
}
}
}
essa é apenas uma interface que crie com uns metodos, vc nao precisa ter essa interface. criei apenas por frescura mesmo hauhuahuauha
/**
*
* @author Andre Heidi Moriya
*/
public interface IReport {
public JasperPrint createReport(String relatorio, String jrprint, String PDF);
public JasperPrint createReport(String relatorio);
public JasperPrint createReport(String relatorio, Integer codigo);
}
para vc usar essa classe faça o seguinte.
Relatorio rel = new Relatorio();
rel.createReport(<Nome do Seu RELATORIO>);
qualquer coisa estou a disposição
falow