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

后端 未结 2 1806
轻奢々
轻奢々 2020-12-05 09:09

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

相关标签:
2条回答
  • 2020-12-05 09:32
    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);
    
    0 讨论(0)
  • 2020-12-05 09:38

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

    0 讨论(0)
提交回复
热议问题