This class can be used at design time to preview the report templates.
This class uses the
JRViewerclass represents this visual component. It can be customized to respond to a particular application's needs by subclassing it. For example, you could add or remove buttons from the existing toolbar.
JasperReports also comes with a simple Swing application that uses the visual
component for viewing the reports. This application helps view reports stored on disk in
*.jrprint proprietary format or in the JRPXML format produced by
the default XML exporter.
This simple Java Swing application is implemented in the
JasperViewer class and is used in almost all the
provided samples for viewing the generated reports.
To view a sample report if you have the Ant build tool installed on your system, go to the desired sample directory and launch the following from the command line:
>ant view or >ant viewXml
JasperViewer- use this class to view generated reports, either as in-memory objects or serialized objects on disk or even stored in XML format.
JasperDesignViewer- use this class to preview report templates, either in JRXML or compiled form.
The report viewers mentioned previously use the visual component represented by the
JRViewer class and its companions. It is in fact a
javax.swing.JPanel component that is capable of displaying generated
reports. It can be easily incorporated into other Java Swing-based applications or
If the functionality of this basic visual component is not sufficient, one can adapt it by subclassing it. For example, to create an extra button on the toolbar of this viewer, extend the component and add that button in the new visual component obtained by subclassing.
Another very important issue is that the default report viewer that comes with the library does not know how to deal with document hyperlinks that point to external resources. It deals only with local references by redirecting the viewer to the corresponding local anchor.
However, JasperReports lets users handle the clicks made on document hyperlinks that
point to external documents. To do this, simply implement the
JRHyperlinkListener interface and add an instance
of this listener class to register with the viewer component, using the
addHyperlinkListener(JRHyperlinkListener) method exposed by the
JRViewer class. By doing this, you ensure that the
viewer will also call the implementation of the
gotoHyperlink(JRPrintHyperlink) method in which
the external references are handled.
There are two ways of rendering the current document page on the viewer component:
The second approach avoids any potential memory problems at high zoom ratios by rendering page content directly onto the view component, but this results in a drop of performance that can be seen when scrolling the page.
Switching between the two rendering methods can be controlled by setting the
net.sf.jasperreports.viewer.render.buffer.max.size configuration property.
The value of this property represents the maximum size (in pixels) of a buffered image
that would be used by the
JRViewer component to render
a report page (the first rendering technique). If rendering a report page requires an
image larger than this threshold (that is, image width x image height > maximum size),
then the report page will be rendered directly on the viewer component.
By default, this configuration property is set to 0, which means that only direct rendering is performed, no matter what the zoom ratio.
© 2001 - 2016 TIBCO Software Inc. www.jaspersoft.com