How to display JasperReports Viewer inside a JPane

2019-01-17 09:14发布

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?

2条回答
成全新的幸福
2楼-- · 2019-01-17 09:24
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);
查看更多
萌系小妹纸
3楼-- · 2019-01-17 09:31

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

查看更多
登录 后发表回答