Java 如何在 JPanel/JFrame 中显示 JasperReports Viewer ..?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3059636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:06:17  来源:igfitidea点击:

How to display JasperReports Viewer inside a JPanel/JFrame..?

javaswingjasper-reports

提问by CarlJohn

I'm a newbie in using JasperReports. In my Swingapplication I want to show JRViewerinside a JPanelor JFrame.

我是使用JasperReports. 在我的Swing应用程序中,我想JRViewer在 aJPanelJFrame.

Can anyone help me out?

谁能帮我吗?

采纳答案by darri

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);

回答by Erick M

The JRViewerclass is a subclass of javax.swing.JPanel, so treat it like a normal JPaneland do your stuff.

这个JRViewer类是 的子类javax.swing.JPanel,所以把它当作一个普通的JPanel来做你的事情。