当内部底部框架为空白时如何缩小框架。?
How shrink a frame when the bottom frames inside are blank.?
所以当最后两个内部框架包含
文本字段(红色框)是空白的。左右主框架也在框架内。但即使只有 4 行,我也总是在报告中得到未使用的 space。
<detail>
<band height="11" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<printWhenExpression><![CDATA[$V{REPORT_COUNT}>1]]></printWhenExpression>
</band>
<band height="71" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="554" height="71" isRemoveLineWhenBlank="true" uuid="603f6666-1471-4d16-b0aa-bde352f18b8e">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<frame>
<reportElement style="Default" stretchType="RelativeToTallestObject" x="0" y="0" width="301" height="50" isRemoveLineWhenBlank="true" uuid="a12bdb49-abd3-4ecf-83db-033e5846174d"/>
<frame>
<reportElement positionType="Float" x="0" y="20" width="300" height="10" isRemoveLineWhenBlank="true" uuid="ec17f3b3-e6e1-4f57-89e1-3499e4aa63cb">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!(EXACT(continitions]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="96082d63-b65e-4461-951d-6f6532ca9fe0">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["Morada"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="227f2a1f-3fc6-4fbf-a680-6d4ec4bbf86b"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[(condditions]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="30" width="300" height="10" isRemoveLineWhenBlank="true" uuid="115c7def-a074-4164-8738-649cecaa095a">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[conditions]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="d46cb243-e8e7-4775-9abb-c8600e44f884">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="" x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="c9f0f6dc-9fc3-49bd-ac4c-7de41ac07633"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[conditions]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="10" width="300" height="10" isRemoveLineWhenBlank="true" uuid="016e4775-e417-4f5c-a4de-b0be970e9d3a">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="e4e78c67-a0c0-4d01-9942-3429ce402bc5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$(field)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="6b3ac9a8-28a5-413e-9348-e9625f94c235">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement x="0" y="0" width="300" height="10" isRemoveLineWhenBlank="true" uuid="7f7b2531-9450-4a9f-b311-625df5ccae4f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" isRemoveLineWhenBlank="true" uuid="c5a3d310-c74f-4546-97b0-18aa4de9a45a">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="649b1963-912c-4902-8052-1320e32e67ab">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
</frame>
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="301" y="0" width="244" height="70" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="c1a1530c-2fca-43d8-a238-f48f3290da29">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<frame>
<reportElement positionType="Float" x="0" y="40" width="244" height="10" isRemoveLineWhenBlank="true" uuid="a96e6e9f-e02f-4e9b-a900-2e55a33df0f3">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition)))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="edb4759b-cf68-4367-8bc4-7e07364ae3c5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" isPrintWhenDetailOverflows="true" uuid="48766f62-03de-407a-a771-6e82e5a4c7ff">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="10" width="244" height="10" isRemoveLineWhenBlank="true" uuid="acbe8ba0-af8d-4e1a-93a8-7305a02839a6">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition)))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="d14807d2-aa00-421f-9dab-7cce0adf758a">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="63e62a4d-9dca-4dca-85f5-515a4ee18d0b">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{locationscope_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="0" width="244" height="10" isRemoveLineWhenBlank="true" uuid="cc62c22d-cc19-4461-ba53-74f4ba733322">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="6ce16cc5-2a18-4b3d-a7f7-17979a0a111b">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="cc7b895b-2e4f-4118-830f-1bde2e181be6">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{scope_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="30" width="244" height="10" isRemoveLineWhenBlank="true" uuid="4c9ae6a0-6534-4952-be6c-7a18d8351a3c">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="1c8aedb1-020b-4d7f-aea2-93b0557b2c23">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="c7ae3de9-2f2d-4178-85b2-bf2091766558">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="20" width="244" height="10" isRemoveLineWhenBlank="true" uuid="8f058c9f-27d5-4f0f-8eac-32a58fa7ad06">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="ba3f46e3-c823-4815-a74d-7a4caa77828f">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="75cce569-0fc5-425b-a9fc-9a42516a4305">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="50" width="244" height="10" isRemoveLineWhenBlank="true" uuid="18fad1eb-f42f-4876-be03-40aac2765875">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[!($F{condition}]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="2e21f092-a95f-42b1-897e-50af56985554">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="a9fe6852-4253-4fb9-a089-d007459655dd">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="60" width="244" height="10" isRemoveLineWhenBlank="true" uuid="c102458f-d273-4611-a851-ed8e83adfead">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[!($F{condntion})]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="80dcd916-f4c8-434d-a833-e864f64ddae5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="5676615c-3ae5-41c6-8cf1-dbdef5cc3a99">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
</frame>
</frame>
</band>
</detail>
在 jasper 报告中,您可以不收缩 元素,而是需要在需要时拉伸它们。
在您的情况下,这意味着报告中的框架需要达到您需要的最小尺寸,然后如果其中有更多内容,您可以拉伸它。
比如你的第一帧
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="554" height="71" isRemoveLineWhenBlank="true" uuid="603f6666-1471-4d16-b0aa-bde352f18b8e">
......
它的最小高度始终为 71,如果它需要更小(当某些组件不显示时),您需要将该值减小到例如 10。
为了解释此行为,我将附上一个小示例,其中一个框架(具有边框)包含 2 个静态文本字段,第二个将基于参数显示。
<?xml version="1.0" encoding="UTF-8"?>
<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="Blank_A4_3" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="53801704-697f-43ac-aed6-9e952be4ab7f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="ShowText2" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="96" splitType="Stretch">
<frame>
<reportElement stretchType="ElementGroupHeight" x="0" y="0" width="545" height="30" uuid="6ca5ba0c-b9c0-4ae9-be7f-e7a372593e94"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="7291cb69-0d98-4ce2-8031-60b5c6df4ebb"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Static text 1]]></text>
</staticText>
<staticText>
<reportElement x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="7df247c0-2c72-4413-83f5-3d4d3aec258c">
<printWhenExpression><![CDATA[$P{ShowText2}]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Static text 2]]></text>
</staticText>
</frame>
</band>
</title>
</jasperReport>
输出
不显示第二个文本字段
显示第二个文本字段
The key concept is that the frame has height="30"
which is the not stretched value (minimum value) and instead it gets stretched to height="60"
if the second text field is displayed.
注意:我正在使用 stretchType="ElementGroupHeight"
,因为 stretchType="RelativeToTallestObject"
已被弃用。
所以当最后两个内部框架包含 文本字段(红色框)是空白的。左右主框架也在框架内。但即使只有 4 行,我也总是在报告中得到未使用的 space。
<detail>
<band height="11" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<printWhenExpression><![CDATA[$V{REPORT_COUNT}>1]]></printWhenExpression>
</band>
<band height="71" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="554" height="71" isRemoveLineWhenBlank="true" uuid="603f6666-1471-4d16-b0aa-bde352f18b8e">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<frame>
<reportElement style="Default" stretchType="RelativeToTallestObject" x="0" y="0" width="301" height="50" isRemoveLineWhenBlank="true" uuid="a12bdb49-abd3-4ecf-83db-033e5846174d"/>
<frame>
<reportElement positionType="Float" x="0" y="20" width="300" height="10" isRemoveLineWhenBlank="true" uuid="ec17f3b3-e6e1-4f57-89e1-3499e4aa63cb">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!(EXACT(continitions]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="96082d63-b65e-4461-951d-6f6532ca9fe0">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["Morada"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="227f2a1f-3fc6-4fbf-a680-6d4ec4bbf86b"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[(condditions]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="30" width="300" height="10" isRemoveLineWhenBlank="true" uuid="115c7def-a074-4164-8738-649cecaa095a">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[conditions]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="d46cb243-e8e7-4775-9abb-c8600e44f884">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="" x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="c9f0f6dc-9fc3-49bd-ac4c-7de41ac07633"/>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[conditions]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="10" width="300" height="10" isRemoveLineWhenBlank="true" uuid="016e4775-e417-4f5c-a4de-b0be970e9d3a">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" uuid="e4e78c67-a0c0-4d01-9942-3429ce402bc5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$(field)]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" uuid="6b3ac9a8-28a5-413e-9348-e9625f94c235">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement x="0" y="0" width="300" height="10" isRemoveLineWhenBlank="true" uuid="7f7b2531-9450-4a9f-b311-625df5ccae4f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="80" height="10" isRemoveLineWhenBlank="true" uuid="c5a3d310-c74f-4546-97b0-18aa4de9a45a">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="58" y="0" width="218" height="10" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="649b1963-912c-4902-8052-1320e32e67ab">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
</frame>
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="301" y="0" width="244" height="70" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="c1a1530c-2fca-43d8-a238-f48f3290da29">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<frame>
<reportElement positionType="Float" x="0" y="40" width="244" height="10" isRemoveLineWhenBlank="true" uuid="a96e6e9f-e02f-4e9b-a900-2e55a33df0f3">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition)))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="edb4759b-cf68-4367-8bc4-7e07364ae3c5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" isPrintWhenDetailOverflows="true" uuid="48766f62-03de-407a-a771-6e82e5a4c7ff">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="10" width="244" height="10" isRemoveLineWhenBlank="true" uuid="acbe8ba0-af8d-4e1a-93a8-7305a02839a6">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition)))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="d14807d2-aa00-421f-9dab-7cce0adf758a">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="63e62a4d-9dca-4dca-85f5-515a4ee18d0b">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{locationscope_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="0" width="244" height="10" isRemoveLineWhenBlank="true" uuid="cc62c22d-cc19-4461-ba53-74f4ba733322">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="6ce16cc5-2a18-4b3d-a7f7-17979a0a111b">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="cc7b895b-2e4f-4118-830f-1bde2e181be6">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{scope_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="30" width="244" height="10" isRemoveLineWhenBlank="true" uuid="4c9ae6a0-6534-4952-be6c-7a18d8351a3c">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})))]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="1c8aedb1-020b-4d7f-aea2-93b0557b2c23">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="c7ae3de9-2f2d-4178-85b2-bf2091766558">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="20" width="244" height="10" isRemoveLineWhenBlank="true" uuid="8f058c9f-27d5-4f0f-8eac-32a58fa7ad06">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<printWhenExpression><![CDATA[!($F{condition})]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="ba3f46e3-c823-4815-a74d-7a4caa77828f">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="75cce569-0fc5-425b-a9fc-9a42516a4305">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="50" width="244" height="10" isRemoveLineWhenBlank="true" uuid="18fad1eb-f42f-4876-be03-40aac2765875">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[!($F{condition}]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="2e21f092-a95f-42b1-897e-50af56985554">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_label}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="a9fe6852-4253-4fb9-a089-d007459655dd">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement positionType="Float" x="0" y="60" width="244" height="10" isRemoveLineWhenBlank="true" uuid="c102458f-d273-4611-a851-ed8e83adfead">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<property name="local_mesure_unity" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
<printWhenExpression><![CDATA[!($F{condntion})]]></printWhenExpression>
</reportElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="100" height="10" uuid="80dcd916-f4c8-434d-a833-e864f64ddae5">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA["field_label"]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="100" y="0" width="144" height="10" uuid="5676615c-3ae5-41c6-8cf1-dbdef5cc3a99">
<property name="local_mesure_unitwidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<textElement>
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{field_value}]]></textFieldExpression>
</textField>
</frame>
</frame>
</frame>
</band>
</detail>
在 jasper 报告中,您可以不收缩 元素,而是需要在需要时拉伸它们。
在您的情况下,这意味着报告中的框架需要达到您需要的最小尺寸,然后如果其中有更多内容,您可以拉伸它。
比如你的第一帧
<frame>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="554" height="71" isRemoveLineWhenBlank="true" uuid="603f6666-1471-4d16-b0aa-bde352f18b8e">
......
它的最小高度始终为 71,如果它需要更小(当某些组件不显示时),您需要将该值减小到例如 10。
为了解释此行为,我将附上一个小示例,其中一个框架(具有边框)包含 2 个静态文本字段,第二个将基于参数显示。
<?xml version="1.0" encoding="UTF-8"?>
<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="Blank_A4_3" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="53801704-697f-43ac-aed6-9e952be4ab7f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="ShowText2" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="96" splitType="Stretch">
<frame>
<reportElement stretchType="ElementGroupHeight" x="0" y="0" width="545" height="30" uuid="6ca5ba0c-b9c0-4ae9-be7f-e7a372593e94"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="7291cb69-0d98-4ce2-8031-60b5c6df4ebb"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Static text 1]]></text>
</staticText>
<staticText>
<reportElement x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="7df247c0-2c72-4413-83f5-3d4d3aec258c">
<printWhenExpression><![CDATA[$P{ShowText2}]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Static text 2]]></text>
</staticText>
</frame>
</band>
</title>
</jasperReport>
输出
不显示第二个文本字段
显示第二个文本字段
The key concept is that the frame has
height="30"
which is the not stretched value (minimum value) and instead it gets stretched toheight="60"
if the second text field is displayed.
注意:我正在使用 stretchType="ElementGroupHeight"
,因为 stretchType="RelativeToTallestObject"
已被弃用。