【问题标题】:Generate iReport from Jtextfield Value of recent window to iReport textfield从最近窗口的 Jtextfield 值生成 iReport 到 iReport 文本字段
【发布时间】:2013-11-27 11:55:10
【问题描述】:

我想从我最近的窗口中的 JtextField 的值而不是从数据库中生成 iReport。

示例我的 CategoryPanel 中有这个 txtCategory (jTextfield)。现在,当我单击 PRINT 按钮时,我想获取 txtCategory 的文本值并将其放在 iReport/JasperReport 内的一个文本字段中。我要怎么做?有人能帮我吗?我在我的 Netbeans 编译器中使用 iReport 插件。谢谢。

【问题讨论】:

  • iReport 只是一个用于构建报表模板的 gui 设计器。你是什​​么意思:I want to generate iReport
  • 我的意思是我想使用 iReport/JasperReport 模板生成报告。我通过我的数据库使用它。通过执行 sql 查询,我得到了我想要保存在 pdf/print 中的报告。但是现在,我想在 iReport 中生成从 jTextfield(而不是数据库)到 textfield 的报告数据。
  • 你可以使用JavaBean Data Sources

标签: java swing user-interface ireport


【解决方案1】:

如果我理解您的问题,您可以将您的 jTextField 数据通过参数传递到报告中。

JasperReport jasperReport;
JasperPrint jasperPrint;
HashMap params = new HashMap();
FileInputStream reportStream;
try {
    FileInputStream reportStream = new FileInputStream(new File("report.jasper");
    HashMap params = new HashMap();
    params.put("TEXT_VALUE", jTextField.getText());
    JasperReport jasperReport = (JasperReport) JRLoader.loadObject(reportStream);
    JasperPrint jasperPrint = JasperFillManager.fillReport(
                jasperReport, params, DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8", root, root));
    JasperViewer jReportsViewer = new JasperViewer(jasperPrint, false);
    jReportsViewer.setFitWidthZoomRatio();
    jReportsViewer.setVisible(true);
    reportStream.close();

在您的报告中,您必须创建类 java.lang.String 或 Object 的参数 TEXT_VALUE。之后,您需要在 textField 中将其定义为 $P{TEXT_VALUE}... 我希望这是您正在寻找的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多