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
How to display JasperReports Viewer inside a JPanel/JFrame..?
提问by CarlJohn
I'm a newbie in using JasperReports. In my Swingapplication I want to show JRViewerinside a JPanelor JFrame.
我是使用JasperReports. 在我的Swing应用程序中,我想JRViewer在 aJPanel或JFrame.
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来做你的事情。

