2
votes

I have an odd problem with Jasperreports (using the Jasper Studio Pro 6.4.2) as the designer.

I have a very simple example showing that the detail band is not dynamically adjusting its height to accommodate the text field's "stretch" property.

As to the settings on the text field, I have the following

  • isStretchWithOverflow="true"
  • positionType="Float"
  • stretchType="RelativeToTallestObject"

The detail band has the following setting:

  • splitType="Stretch"

The full code of the report is below:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports 
Library version 6.4.1  -->
<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="NSXGroupMemberServers" columnCount="4" printOrder="Horizontal" pageWidth="461" pageHeight="792" columnWidth="115" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" uuid="f155815a-db1d-4ada-a8e6-b753eec591d1">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="NSX Rules"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <parameter name="GroupID" class="java.lang.Integer"/>
    <queryString language="SQL">
        <![CDATA[Select ServerName from ServerInventoryTable SIT
Inner Join
ServerToGroupTable SGT on SIT.ServerID = SGT.ServerID
Inner Join GroupTable GT on SGT.GroupID = GT.GroupID
Where GT.GroupID =  $P{GroupID} ]]>
    </queryString>
    <field name="ServerName" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="20" splitType="Stretch">
            <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="0" y="0" width="25" height="20" backcolor="#F2F0F0" uuid="bc85ea8a-bc71-483a-994a-a5facfbd752b">
                    <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <box leftPadding="0">
                    <topPen lineWidth="0.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="0.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement verticalAlignment="Top">
                    <font size="8"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{ServerName}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

I believe that the issue lies somewhere in the detail band behavior because as part of troubleshooting, I set the field abnormally short (as you can see above with only a 25px width field). If I set the detail band height manually to say 100px, I can see the text field grow vertically (when running the report) to accommodate the text, so the text field (at least to me) seems to be acting properly.

Does anyone know if I am missing something here? I've checked my settings against numerous posts such as [Stretch with overflow Detail band not working as expected Stretch with overflow Detail band not working as expected .

Any help is greatly appreciated.

Thank you

1

1 Answers

2
votes

The detail band in your report doesn't stretch because the report has horizontal filling order (printOrder="Horizontal").

Quoting from the documentation:

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.

If you need horizontal filling with stretching elements, you can use a list component instead of report bands. Lists with horizontal printing order allow the contents to stretch and align. You can see an example here.

Converting the report to use a list component involves creating a subdataset and moving the query to the dataset. The list component could be placed into the report title or summary bands.