Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasper Viewer set title

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

like image 656
Débora Avatar asked Oct 26 '11 13:10

Débora


2 Answers

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{
   //...
}
like image 82
gtiwari333 Avatar answered Oct 11 '22 15:10

gtiwari333


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();
like image 43
Marc Nuri Avatar answered Oct 11 '22 15:10

Marc Nuri