虽然已经初始化并添加到框架中,但JRViewer在预期框架上不可见

时间:2016-03-11 06:56:32

标签: java swing jasper-reports

在一帧上按钮的点击事件我写了这段代码

JasperPrint jasperPrint = new business_logics.Client().generateReport(this);
Report report = new Report(jasperPrint);

,核心代码就像这样

public JasperPrint generateReport(Component o) {
    try {
        JasperPrint jasperPrint = null;
        if (hm == null) {
            hm = new HashMap();
        }

        try {
           String source="Client.jasper";
           jasperPrint = JasperFillManager.fillReport(source, hm, new ConnectionSeeker().giveConnection(o));
        } catch (JRException e) {
           System.err.println(""+e.getMessage());
        }
        return jasperPrint;
    } catch (Exception ex) {
        System.err.println(""+ex);
        return null;
    }
}

我想要显示JRViewer的框架是这样的:

public class Report extends javax.swing.JFrame {

    private JRViewer viewer;

    public Report(JasperPrint  j) {
       initComponents();
       viewer = new JRViewer(j);
       add(viewer);
       pack();
       this.setVisible(true);
    }
}

0 个答案:

没有答案