[英]Dynamically adding textField in JasperReports
Is there a way to dynamically add textFields to the columnFooter in a Jasper Report. 有没有一种方法可以在Jasper报表中将textFields动态添加到columnFooter中。
I have situation where I might have to use: 我有可能不得不使用的情况:
<columnFooter>
<band height="21" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="50" height="21"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["Example text...."]]></textFieldExpression>
</textField>
</band>
or 要么
<columnFooter>
<band height="42" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="50" height="21"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["Example text...."]]></textFieldExpression>
</textField> <textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="50" height="21"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["More example text...."]]></textFieldExpression>
</textField>
</band>
(Or add any number of textFields. Since I do not know how many will be added, I need to dynamically resize the band somehow) I'm looking for a way to dynamically do this in Java and not have to hardcode it in the jrxml file. (或添加任意数量的textFields。由于我不知道要添加多少个textField,因此我需要以某种方式动态调整带的大小)我正在寻找一种方法来在Java中动态执行此操作,而不必在jrxml中对其进行硬编码文件。 Thanks 谢谢
使用第二种方法在textFields上设置PrintWhenExpression并在此textFields的属性上设置“在空白时删除行”复选框。
If your report is created dynamically as JRDesign you can use the following: 如果您的报告是作为JRDesign动态创建的,则可以使用以下方法:
JRDesignBand band = (JRDesignBand) jasperDesign.getColumnFooter();
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0);
textField.setY(0);
band.addElement(textField);
I'm sorry to say but after years of working with JR Java API I have a feeling it was designed to print over fixed layout of document. 我很遗憾地说,但是经过多年与JR Java API的合作,我感到它旨在打印在文档的固定布局上。 What could help in your case: if you know max number of fields that might appear, just add all them to the band, and set "remove line when blank" flag to true for each of them. 在您的情况下可能有用的方法:如果您知道可能出现的最大字段数,只需将它们全部添加到波段,然后将每个字段的“空白时删除行”标志设置为true。 It will collapse unused fields. 它将折叠未使用的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.