Crystal Report Viewer
Friday, June 27. 2008
Today I figured out how to preview Crystal reports that are populated with a list of POJO objects. Here is the code to do it.
The ReportViewerBean can be found in the Eclipse plugins directory, in the ReportViewer.jar library. Make sure to have the .rpt file available on the classpath, as well as your CRConfig.xml file.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
// create a viewer
ReportViewerBean viewer = new ReportViewerBean();
viewer.init(new String[0], null, null, null);
// create a window
JFrame frame = new JFrame("Crystal Report Viewer");
frame.setTitle("Crystal Report Viewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(viewer, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setVisible(true);
// display the report
IReportSource reportSource = report.getReportSource();
viewer.setReportSource(reportSource);
viewer.start();
} catch (Exception exception) {
System.out.println(exception.toString());
}
}
});