aanderso Posted January 15, 2009 Share Posted January 15, 2009 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 More sharing options...
C-Box Posted January 16, 2009 Share Posted January 16, 2009 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")hthC-Box Link to comment Share on other sites More sharing options...
aanderso Posted January 16, 2009 Author Share Posted January 16, 2009 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? Link to comment Share on other sites More sharing options...
C-Box Posted January 20, 2009 Share Posted January 20, 2009 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.TRUEshould also work (for all reports) hthC-Box Link to comment Share on other sites More sharing options...
aanderso Posted January 20, 2009 Author Share Posted January 20, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now