2004 IR Help Posted August 22, 2006 Share Posted August 22, 2006 By: twr2 - twr2 Large string not showing in TextField 2005-05-27 11:59 Here's the an example: <textField> <reportElement x="0" y="-12" width="20"height="11"/> <textElement textAlignment="Left" > <font reportFont="Font_Small" /> </textElement> <textFieldExpression class="java.lang.String"> $P{OrderInfo} </textFieldExpression> </textField> If the text to display is say: "A B C D E F G H I", then part of the string is cut off and only part shows (i.e. A B C) but if the string is say: "ABCDEFGHI" then none of the text is shown. Apparently words can't be split, so if the complete word is too large for the textField, it is completely omitted instead of truncating it. Obviously isStretchWithOverflow="true" won't work as the word will always be too large (and I actually don't want the text to wrap). Is there a way to make it truncate? Thanks By: alanHardwick - alan314 RE: Large string not showing in TextField 2005-06-06 00:38 Did you ever find a solution to this problem?, I have exactly the same problems with printing customer names on a 1 line text field. i.e. "Bob IHaveAnExtremelyLongSurname" comes out as "Bob", and would prefer to chop the end of his surname off rather than just display up to the 1st space. Found similar problems on the forum but with none with a solution. Have actually done this report purely withing Java code but cant find any methods to turn off word wrap in my customTextField.. i.e. String text = "Bob IHaveAnExtremelyLongSurname"; JRPrintText textField = new JRBasePrintText(); textField.setX(left); textField.setY(top); textField.setWidth(width); textField.setHeight(height); textField.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT); textField.setLineSpacingFactor(1); textField.setFont(font); textField.setText(text); Thnx Al. By: alanHardwick - alan314 RE: Large string not showing in TextField 2005-06-07 22:53 Any suggestions anyone? By: ren - remaba RE: Large string not showing in TextField 2005-06-08 15:50 you could use the substring method. if(text.length > reportelement.width) { text.substring(0. reportelement.width) } By: alanHardwick - alan314 RE: Large string not showing in TextField 2005-06-08 22:44 Thanks for the suggestion but surely this wont work as text.length will return the length (no of chars) of the string and reportelement.width will return pixels... and of course fonts arent fixed width to complicate matters.. If there was a way to determine the size of a string in pixels (after specifying the font) then I guess could use a variant of this code...WIll see if can work this out. Thanks Al By: Denny Valliant - xenden RE: Large string not showing in TextField 2005-06-10 00:40 I think courier is "fixed width", meaning each char is the same width, but don't know if it works this way in jasperreports... good luck... By: alanHardwick - alan314 RE: Large string not showing in TextField 2005-06-10 03:50 Yep, u are right! Courier is fixed width, didnt know that!. Unfortunatly this is for an invoice report and already using Arial.... By: J. Brett Howell - jbretthowell RE: Large string not showing in TextField 2005-06-14 14:28 There are some methods in the AWT api that can help you figure out the width of a string. For instance: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/FontMetrics.html#stringWidth(java.lang.String) By: alanHardwick - alan314 RE: Large string not showing in TextField 2005-06-14 23:05 OK great, this seems to be what I want. However... not an AWT expert but I believe I can get the FontMetrics from the JPrint object, but I cant seem to figure out how to get the java.awt.font from a JRDesignReportFont (it doesnt appear to be a subclass so cannot cast)... Will try and figure out...(unless anyone can help on this).! 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