问题
Currently I use the attribute isStretchWithOverflow to break the lines when the content in text field is too long. It works. But I want to know how can I determine the way it breaks lines.
Below is the snippet of my jrxml file:
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" width="150" height="20"/>
<box leftPadding="15">
</box>
<textFieldExpression><![CDATA[$F{content}]]></textFieldExpression>
</textField>
For the content like
oh my god test="longstring" abcdefg hijk
I want "longstring" is regarded as a word. So my imagine output is
oh my god test=
"longstring" abcdefg
hijk
But the actual output is
oh my god test="
longstring" abcdefg
hijk
Another problem is similar
The original content is
abc.def/hij/k.lmnopqrstu
I want
abc.def/
hij/k.
lmnopqrstu
But the actual output is
abc.
def/hij/k.
lmnopqrstu
It does not break the line when it meet "/"
Is there any way I can do what I want?
回答1:
The net.sf.jasperreports.engine.fill.TextMeasurer implementation (of net.sf.jasperreports.engine.fill.JRMeasuredText interface) class uses the java.text.BreakIterator interface as implemented by the private RuleBasedBreakIterator class. The RuleBasedBreakIterator reads a file supplied with the JDK that defines the characters on which to perform line breaks on. Since the RuleBasedBreakIterator class is private I have not found an easy way to change the default behavior. Replacing net.sf.jasperreports.engine.fill.TextMeasurer with an alternate implementation is possible by modifying the following properties:
#Default text measurer
net.sf.jasperreports.text.measurer.factory=default
net.sf.jasperreports.text.measurer.factory.default=net.sf.jasperreports.engine.fill.TextMeasurerFactory
This in practice may not be advisable unless you can implement the robust breaking logic in the JDK with your customizations.
An alternative for some may be to use IBM JDK that does not ICU4J that provides a customizable implementation of RuleBasedBreakIterator as decsribed here:
http://sujitpal.blogspot.com/2008/05/tokenizing-text-with-icu4js.html
来源:https://stackoverflow.com/questions/12174751/ireport-issue-with-isstretchwithoverflow