JasperReports中子报表下方浮动文本框无法拉伸至带区高度求助
JasperReports 6.0.0 子报表拉伸后下方文本框消失问题
我使用JasperReports 6.0.0创建了一个两列报表:第一列为文本框,第二列从上到下依次是子报表和文本框。需求是让子报表下方的文本框能够拉伸以填充子报表下方的剩余空间,但遇到异常情况:
- 当子报表仅包含一个元素时,文本框能正常拉伸显示;
- 当子报表包含多个元素(实际高度超过初始设置的20px)时,文本框直接消失(已确认未被遮挡)。
我的分析:只有当子报表实际高度未超过初始设置高度时,文本框才会显示。如果关闭文本框的拉伸功能,无论子报表有多少元素它都能正常显示,但我需要它具备拉伸能力。
主报表代码
<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.0.0.final using JasperReports Library version 6.0.0 --> <!-- 2023-08-23T22:29:24 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="monitoringBulletinRainSensors" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="dc5d5b62-3121-47f6-bc9c-a0c86a6de260"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="test"/> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA["C:\Users\<user>\JaspersoftWorkspace\MyReports\"]]></defaultValueExpression> </parameter> <queryString language="json"> <![CDATA[]]> </queryString> <field name="text" class="java.lang.String"/> <detail> <band height="30" splitType="Prevent"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField isStretchWithOverflow="true"> <reportElement key="" stretchType="RelativeToBandHeight" x="0" y="0" width="50" height="30" uuid="17091a86-28eb-4f4b-814e-2049fc13b754"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <box> <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textElement> <font size="16"/> </textElement> <textFieldExpression><![CDATA[$F{text}]]></textFieldExpression> </textField> <subreport> <reportElement x="50" y="0" width="160" height="20" isPrintInFirstWholeBand="true" backcolor="#FFFFFF" uuid="d8d61ef2-ee12-437a-be7d-9514dc16438d"> <property name="com.jaspersoft.studio.unit.y" value="pixel"/> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <property name="local_mesure_unitwidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="px"/> </reportElement> <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("children")]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test_child.jasper"]]></subreportExpression> </subreport> <textField isStretchWithOverflow="true"> <reportElement positionType="Float" stretchType="RelativeToBandHeight" x="50" y="20" width="160" height="10" uuid="23a8ffa1-34a5-437d-9dc3-1e55a571b2f4"/> <box> <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textElement> <font size="16"/> </textElement> <textFieldExpression><![CDATA["This text field should stretch"]]></textFieldExpression> </textField> </band> </detail> </jasperReport>
子报表代码
<?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 6.0.0.final using JasperReports Library version 6.0.0 --> <!-- 2023-08-23T17:48:48 --> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test_child" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="6ee7b94c-7f06-43f8-a02a-461787c5be45"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <queryString> <![CDATA[]]> </queryString> <field name="text" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <detail> <band height="20" splitType="Prevent"> <textField isStretchWithOverflow="true"> <reportElement positionType="Float" stretchType="RelativeToBandHeight" x="0" y="0" width="160" height="20" uuid="bcfd27d0-fc93-42bd-82fb-74a8d95ed706"> <property name="local_mesure_unitheight" value="pixel"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <property name="local_mesure_unity" value="pixel"/> <property name="com.jaspersoft.studio.unit.y" value="px"/> </reportElement> <box> <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/> </box> <textElement> <font size="16"/> </textElement> <textFieldExpression><![CDATA[$F{text}]]></textFieldExpression> </textField> </band> </detail> </jasperReport>
JSON数据源(可修改children数量模拟两种场景)
{ "text": "This is a very very very very very very very long text", "children": [ { "text": "This is a short text" }, { "text": "This is a short text" }, { "text": "This is a short text" } ] }
内容的提问来源于stack exchange,提问作者zcb
相关产品推荐
相关产品推荐

