7

I'm a newbie in using JasperReports. In my Swing application I want to show JRViewer inside a JPanel or JFrame.

Can anyone help me out?

Alex K
  • 22,315
  • 19
  • 108
  • 236
CarlJohn
  • 727
  • 2
  • 9
  • 20

2 Answers2

19
JRDataSource dataSource = ...;

Map parameters = new HashMap();
parameters.put("id", 42);

JasperReport report = (JasperReport) 
        JRLoader.loadObject("c:/reports/report.jasper");

JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);

JFrame frame = new JFrame("Report");
frame.getContentPane().add(new JRViewer(jasperPrint));
frame.pack();
frame.setVisible(true);
darri
  • 562
  • 1
  • 5
  • 10
1

The JRViewer class is a subclass of javax.swing.JPanel, so treat it like a normal JPanel and do your stuff.

dur
  • 15,689
  • 25
  • 79
  • 125
Erick M
  • 465
  • 4
  • 9