Here is how I show the Jasper report in swing applications.
JasperViewer.viewReport(jasperPrint, true);
Then when the report is viewed, the report viewer's title is "Jasper Viewer" . I want to change it and set my own title name. My other question is how to directly send the report to the print without viewing.Please give any sample code.Thank you
What I normally do is :
JasperViewer jv = new JasperViewer(jasperPrint, false);
jv.setTitle("Report-Title");
jv.setVisible(true);
This works because, JasperViewer is a JFrame -
public class JasperViewer extends JFrame{
//...
}
JasperViewer.viewReport(...)
is a wrapper class that creates and shows a JasperViewer
JFrame
with a JRViewer
panel.
Using this method you can't access the underlying JFrame
, so you can't change the frame title.
You can try to create your own JasperViewer
frame using the public constructor, and then set the title using the setTitle(...)
method.
Another and recommended approach is to create a custom JDialog
with a JRViewer
panel.
To print your report without viewing:
final JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();
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