jimiohara Posted March 7, 2008 Share Posted March 7, 2008 Hi, I have implemented a dynamic column table report using the JRDesign API, and have found that the amount of text of some of the column headers is too big to fit in the static text elements I have constructed. I was wondering if there is anyway to find the length of the string in the text elements, or if anyone knows how to resize a text element so that it will allow the whole string to display? Thanks,James Link to comment Share on other sites More sharing options...
micekmoj Posted March 7, 2008 Share Posted March 7, 2008 Why don't you use textField, and then set the property stretch with overflow = true, instead of static text? Link to comment Share on other sites More sharing options...
jimiohara Posted March 12, 2008 Author Share Posted March 12, 2008 Yes that would fix a problem in the short term but what happens if the textbox overflows onto another column header textbox? Will that happen if a long string? What I would like to do is to build the textboxes depending on the length of the strings, or on where the last text box ended. Link to comment Share on other sites More sharing options...
lucianc Posted March 13, 2008 Share Posted March 13, 2008 jimiohara wrote:I was wondering if there is anyway to find the length of the string in the text elements You can use the internal JasperReports text measurer to determine the required height for a static text. See the following sample code:Code: JasperDesign jasperDesign = new JasperDesign(); jasperDesign.setName("jasper"«»); JRDesignStyle style = new JRDesignStyle(); style.setFontName("Helvetica"«»); style.setFontSize(12); jasperDesign.addStyle(style); JRDesignStaticText text = new JRDesignStaticText(jasperDesign); text.setX(0); text.setY(0); text.setWidth(100); text.setStyle(style); text.setText("I was wondering if there is anyway to find the length of the string in the text elements"«»); Map attributes = new HashMap(); attributes.putAll(JRFontUtil.setAttributes(attributes, text)); JRStyledText styledText = JRStyledTextParser.getInstance().getStyledText(attributes, text.getText(), text.isStyledText()); JRMeasuredText measuredText = JRTextMeasurerUtil.createTextMeasurer(text).measure(styledText, 0, jasperDesign.getPageHeight(), false); text.setHeight((int) Math.ceil(measuredText.getTextHeight())); JRDesignBand title = new JRDesignBand(); title.setHeight(300); title.addElement(text); jasperDesign.setTitle(title); JasperDesignViewer.viewReportDesign(jasperDesign); HTH,Lucian Link to comment Share on other sites More sharing options...
edensh Posted May 24, 2008 Share Posted May 24, 2008 Hi, Is this API accessible from within an already compiled report? Otherwise, how can horizontal dynamic text width resize be accomplished? What I'm trying to do is to have a non-transparent text on top of the top line of a rounded rectangle, creating a great grouping effect (as a generic subreport). Because the text is non transparent, the width of the element must be a function of the width of the actual text used. Does this make sense? Is it possible at all? size=397]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/border.jpgPost edited by: edensh, at: 2008/05/23 21:31 Link to comment Share on other sites More sharing options...
lucianc Posted May 27, 2008 Share Posted May 27, 2008 JasperReports text fields only stretch vertically, the horizontal axis layout is pretty much fixed (with the exception of crosstabs) when running reports. You can change element widths in compiled reports (via JRElement.setWidth), but you won't be able to use the JR text measurer (without modifying/extending it) to determine how wide a specific text is. A solution might be to create a wide transparent text field, and use styled text to set a text background:Code:<textField> .. <textElement textAlignment="Center" isStyledText="true"/> <textFieldExpression><![CDATA[ "<style backcolor="white">" + $P{TITLE} + "</style>" ]]></textFieldExpression> </textField> Regards,LucianPost edited by: lucianc, at: 2008/05/27 07:56 Link to comment Share on other sites More sharing options...
edensh Posted May 28, 2008 Share Posted May 28, 2008 actually, this is quite a good hack! works well; nicely done. thanks. 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