Text field truncating when space between words

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

aanderso's picture
283
Joined: Aug 15 2007 - 6:58am
Last seen: 16 years 1 month ago

4 Answers:

Try to play around with the property:

net.sf.jasperreports.text.truncate.at.char  (set this to true)

this shoud allow the textfield to fill up to the last character

 

(in iReport it's within the menu "edit" --> "custom properties")

hth

C-Box

C-Box's picture
23943
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 weeks 5 days ago
Thanks, C-Box! Unfortunately, I am not using IReports, and JasperAssistant (my version) does not list this property. Can you tell me where the DTD/Schema is for JR 2.0.2 or 2.0.3?
aanderso's picture
283
Joined: Aug 15 2007 - 6:58am
Last seen: 16 years 1 month ago

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

C-Box's picture
23943
Joined: Jul 19 2006 - 5:58pm
Last seen: 3 weeks 5 days ago

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></td></tr></tbody></table>
aanderso's picture
283
Joined: Aug 15 2007 - 6:58am
Last seen: 16 years 1 month ago
Feedback