问题
Is it possible to wrap text in a groupHeader? I have it working in the detail section, but the text within the group does not seem to want to wrap. I have tried every combination for wrapping I could think of or find from google.
<style name="reportProject" isDefault="false" fontName="Times" fontSize="10" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/>
<group name="PROJHEADER" minHeightToStartNewPage="60">
<groupExpression><![CDATA[$F{projectHeader}]]>
</groupExpression>
<groupHeader>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[Boolean.valueOf($F{projectHeader}.length() > 0)]]>
</printWhenExpression>
<textField isStretchWithOverflow="true" isBlankWhenNull="true"
evaluationTime="Group" evaluationGroup="PROJHEADER" bookmarkLevel="1">
<reportElement positionType="Float" style="reportProject" mode="Opaque" x="0" y="5"
width="515" height="15" backcolor="#C0C0C0"
stretchType="RelativeToBandHeight"/>
<box leftPadding="10">
<bottomPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle" />
<textFieldExpression class="java.lang.String"><![CDATA[$F{projectHeader}]]>
</textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
回答1:
Setting the isStretchWithOverflow property with true value helps me.
The sample:
<group name="citygr">
<groupExpression><![CDATA[$F{CITY}]]></groupExpression>
<groupHeader>
<band height="20">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY} + " text1 txt2 longtext3 verylonglongtxt4 long1234567890verylongtext5 txt6 text6 longtext7"]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
The result will be:
I'm using the iReport 4.1.3.
You can also try to set net.sf.jasperreports.export.pdf.force.linebreak.policy property. Just add this this property in your jrxml file. You can read about this property here.
The sample:
<jasperReport ...>
<property name="net.sf.jasperreports.export.pdf.force.linebreak.policy" value="true"/>
回答2:
This is what I ended up with, that works.
<jasperReport ...>
<property name="net.sf.jasperreports.export.pdf.force.linebreak.policy" value="true"/>
.....
<group name="PROJHEADER" minHeightToStartNewPage="60">
<groupExpression><![CDATA[$F{projectHeader}]]>
</groupExpression>
<groupHeader>
<band height="40" splitType="Stretch">
<printWhenExpression><![CDATA[Boolean.valueOf($F{projectHeader}.length() > 0)]]></printWhenExpression>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="reportProject" x="0" y="5"
width="400" height="15" backcolor="#C0C0C0"/>
<textElement textAlignment="Left" verticalAlignment="Middle" />
<textFieldExpression class="java.lang.String"><![CDATA[$F{projectHeader}]]>
</textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
来源:https://stackoverflow.com/questions/8919645/the-text-is-rendering-clipped-ignoring-isstretchwithoverflow-property-value-usin