Question

I am using JasperReports 4.0.2 (not tied to it in the long run, but for now we are).

I am having a problem with a sub-report which is set up to support 3 columns of data. I have 2 text fields which are being printed, and when the data is too long for the text field it is being truncated. After following advice in JasperReport - wrap text to show long text in textfield post I am still struggling to get the text field to overflow properly to display the data.

Here is my report file:

<?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="record" language="groovy" columnCount="3" printOrder="Horizontal" pageWidth="572" pageHeight="752" columnWidth="157" columnSpacing="50" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <field name="geoName" class="java.lang.String"/>
    <field name="count" class="java.lang.Integer"/>
    <variable name="count" class="java.lang.String">
        <variableExpression><![CDATA[new java.text.DecimalFormat("###,###,###,###").format($F{count})]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="15" splitType="Stretch">
            <textField isStretchWithOverflow="true">
                <reportElement x="0" y="0" width="90" height="15" stretchType="RelativeToBandHeight" positionType="Float"/>
                <textElement verticalAlignment="Middle">
                    <font fontName="Arial"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{geoName}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement x="90" y="0" width="67" height="15" stretchType="RelativeToBandHeight" positionType="Float"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font fontName="Arial"/>
                </textElement>
                <textFieldExpression><![CDATA[$V{count}]]></textFieldExpression>
             </textField>
             <line>
                <reportElement x="182" y="0" width="1" height="15" forecolor="#CCCCCC" stretchType="RelativeToBandHeight" positionType="Float"/>
            </line>
        </band>
    </detail>
</jasperReport>

The report generally works properly and expands horizontally as it should, but if the data in either of the text fields is too long, it simply truncates it. The only workaround I have is to increase the band size, but that doesn't look good. I have also tried the isPrintWhenDetailOverflows="true" flag as well.

Was it helpful?

Solution

I have found my answer, and it is just a limitation of jasper.

http://jasperreports.sourceforge.net/sample.reference/horizontal/index.html

When filling report templates horizontally, dynamic text fields inside the detail section do not stretch to their entire text content, because this might cause misalignment on the horizontal axis of subsequent detail sections. The detail band actually behaves the same as the page and column footers, preserving its declared height when horizontal filling is used.

So long story short, when filling horizontally you can't expect a vertical expansion as well, bummer!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top