Jump to content
Changes to the Jaspersoft community edition download ×

Text field truncating when space between words


aanderso

Recommended Posts

We are using JR 2.0.2, and the forms were designed with JasperAssistant (and usually hand-modified via xml editor).

I have a text field on the form that is wide enough to hold 16 characters using Courier New 10 point, which I am using to hold names. The names occur as LAST, FIRST <other freeform text>. 

When the name exceeds 16 characters, the first name -- or <other freeform text> -- containing space often does not print. However, if the input to the field is 22+ characters or more WITHOUT intervening spaces, then the field is truncated at 22. For example, two names are "THOMPSON, CALVIN" and "THOMPSON, CALVINA". The first example prints the entire name ( "THOMPSON, CALVIN"), but the second leaves off the "CALVINA"  entirely and prints only ("THOMPSON, ")!

 What I'd expect it to do is truncate the terminal 'A' in Calvina.  In other words, the text field should print as much text as possible for the available field size and font.

I could not find any attribute that changes this behaviour. The report is being run locally on my own machine, and whether I use the Sun JDK 1.5 or IBM (RAD 7) JDK (also supposedly 1.5). We cannot allow the field to grow on overflow, and the line already has too many fields to make the name field bigger.

Have I missed something, or is this a bug? Is there a fix in some later version?

Thanks for the help,

Andy

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Just add this to your jasperReport Tag (for one report):

<property name="net.sf.jasperreports.text.truncate.at.char" value="Boolean.TRUE" />

 

or put it into a file "JasperReports.properties that is within the classpath.

net.sf.jasperreports.text.truncate.at.char=Boolean.TRUE

should also work (for all reports)

 

hth

C-Box

Link to comment
Share on other sites

It turns out there is a different way also. In JasperAssistant editor, just double-click the textfield and enter:

 

($F{name}.trim().length()> 25 ? $F{name}.substring(0,24) : $F{name}.trim())

This results in the XML below, and will fill out the field nicely. The only downside is that if you change the font size or style (or the field size), you'll have to redo the tertiary above or the results may not be quite what you expect.

Thanks for the help!

Code:
<textField isStretchWithOverflow="true" hyperlinkType="None"><reportElement isPrintRepeatedValues="false" x="92" y="1" width="140" height="12"/>   <textElement textAlignment="Left" verticalAlignment="Middle">      <font fontName="Courier New" size="9" pdfFontName="Courier"/>   </textElement>   <textFieldExpression class="java.lang.String" ![CDATA[($F{cmname}.trim().length()> 25 ? $F{cmname}.substring(0,24) : $F{cmname}.trim())]]></textFieldExpression></textField>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...