Estava aprendendo a gerar relatorios com o iReport e JasperReport, ate ai tudo bem, então resolvi fazer um teste, criei uma classe main só com um JFrame e um botão que chama outra classe responsavel por gera e mostrar o relatorio. Funcionou, o problema é que quando eu fecho o relatorio ele tambem fecha a classe main e finaliza a aplicação. Alguem tem ideia do que eu estou fazendo errado !?!? ou o JasperViewer funciona assim mesmo!?!?!?
Metodo Main
package relatorios;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRException;
public class main extends javax.swing.JFrame {
public main() {
initComponents();
setExtendedState(MAXIMIZED_BOTH);
ButtonHandler bh = new ButtonHandler();
btnPdf.addActionListener(bh);
}
private void initComponents() {
jFrame1 = new javax.swing.JFrame();
btnPdf = new javax.swing.JButton();
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnPdf.setText("PDF");
btnPdf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPdfActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnPdf, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(611, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnPdf)
.addContainerGap(371, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnPdfActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == btnPdf) {
try {
RelatorioBibliotecaPessoal rel = new RelatorioBibliotecaPessoal();
rel.geraRelatorio();
} catch (JRException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
public static void main(String args[]){
//main main = new main();
new main().setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JButton btnPdf;
private javax.swing.JFrame jFrame1;
// End of variables declaration
}
