JasperReport – wrap text to show long text in textfield

I found the answer myself :

I did some extra research about the properties of textField and rectangle components. And found that I need to set the following properties.

For rectangle :

        <rectangle>
            <reportElement stretchType="RelativeToBandHeight" ... />
        </rectangle>

For textField :

        <textField isStretchWithOverflow="true">
            ...
        </textField>

Output as expected :

enter image description here

The <detail> ...</detail> section after correction :

<detail>
        <band height="21" splitType="Stretch">
            <rectangle>
                <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="88" height="21"/>
            </rectangle>
            <textField isStretchWithOverflow="true">
                <reportElement x="2" y="0" width="84" height="21"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{personName}]]></textFieldExpression>
            </textField>
            <rectangle>
                <reportElement stretchType="RelativeToBandHeight" x="88" y="0" width="122" height="21"/>
            </rectangle>
            <textField isStretchWithOverflow="true">
                <reportElement x="90" y="0" width="118" height="21"/>
                <textElement verticalAlignment="Middle"/>
                <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
            </textField>
        </band>
    </detail>

UPDATE

You can also set property net.sf.jasperreports.print.keep.full.text to true to achieve that across your all reports.

Leave a Comment