When a JasperViewer
appear and I close it, the main frame / parent also closed. How to prevent this?
This is my code..
private void cmdprintidMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
try {
JasperDesign jasperDesign = JRXmlLoader.load("report12.jrxml");
String sql = "select * from db1 where Company LIKE '" + txtcompany.getText() + "%'";
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(sql);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
Change this:
JasperViewer.viewReport(jasperPrint);
to JasperViewer.viewReport(jasperPrint, false);
This will work properly.
No need to do anything, other than to call the alternative:
JasperViewer(jasperPrint, **false**);
JasperViewer.viewReport(jasperPrint, **isExitOnClose**);
The JasperViewer has alternative constructor/method call which receives boolean param: exitOnClose
I don't know if you've found your own way around but I think this is the best one.
JasperViewer(jasperPrint, false);
You just have to pass false with jasperviewer
so the parent window won't close.
Change:
JasperViewer.viewReport(jasperPrint);
To:
JasperViewer.viewReport(jasperPrint);
JasperViewer.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
It would seem theJasperViewer
is using JFrame.EXIT_ON_CLOSE
which will cause System.exit(n)
to be called, thus ending the JVM.
By using JFrame.DISPOSE_ON_CLOSE
instead, only that frame is ended & disposed of.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With