如何在一个被修剪的textField底部对齐textFields?

时间:2016-03-03 13:33:45

标签: jasper-reports

我在使用Jasper报告时遇到了问题。

在我的报告中,我正在尝试对齐textFields,如:

${name}                      ${field1}
${age}                       ${field2}
${address}                   ${field3}

textField ${name}能够stretchWithOverflow导致它与${field1}重对。

如果textField ${name}延伸,我希望获得${field1}${name}上的最后一行对齐的结果。

${name}                      
${name}(stretched)           ${field1}
${age}                       ${field2}
${address}                   ${field3}

我读了很多论坛但找不到解决方案。

1 个答案:

答案 0 :(得分:1)

您可以使用positionType="FixRelativeToBottom"属性

来实现此目的

示例

<?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="csvTest" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="601103bc-66ab-45a5-8422-ccb6f3e02ec2">
    queryString>
        <![CDATA[]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="age" class="java.lang.String"/>
    <field name="adress" class="java.lang.String"/>
    <field name="field1" class="java.lang.String"/>
    <field name="field2" class="java.lang.String"/>
    <field name="field3" class="java.lang.String"/>
    <detail>
        <band height="60" splitType="Stretch">
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" x="0" y="0" width="100" height="20" uuid="bf6b550c-f37d-4e10-b8dd-1d91c4e6905a"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="0" y="20" width="100" height="20" uuid="cbcc18ce-a1c8-4659-b30e-c1a360392b0a"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{age}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="Float" x="0" y="40" width="100" height="20" uuid="ffda046d-87cc-4f51-8568-99c19a54ed7e"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{adress}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="FixRelativeToBottom" x="100" y="0" width="100" height="20" uuid="2110cf81-a71d-45c0-9bd9-d26d69167860"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="FixRelativeToBottom" x="100" y="20" width="100" height="20" uuid="2c7fd4ec-324f-4c03-9b13-c3e1bb83d6ad"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement positionType="FixRelativeToBottom" x="100" y="40" width="100" height="20" uuid="6371e8da-43d8-43e6-86a3-65bedd87f030"/>
                <textElement verticalAlignment="Bottom">
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="0" y="0" width="200" height="1" uuid="719e26b2-88ef-4558-a6d6-2c0589e04638"/>
            </line>
        </band>
    </detail>
</jasperReport>

示例数据:

+-----------------------------+-----+------------+-------------+-------------+-------------+
|            name             | age |   adress   |   field1    |   field2    |   field3    |
+-----------------------------+-----+------------+-------------+-------------+-------------+
| Very long name that stretch |  12 | Selvarella | field1Value | field2Value | field3Value |
| Shorty                      |  13 | New York   | field1Value | field2Value | field3Value |
+-----------------------------+-----+------------+-------------+-------------+-------------+

<强>结果

Result

注意:如果您有多个字段在相同的细节范围内拉伸,它会变得更复杂,在这些情况下,您可能需要使用子报告来获得正确的布局。

有关详细信息,请参阅Jasper Report stretch sample