Jump to content
We've recently updated our Privacy Statement, available here ×

Stretch problem


byteryder

Recommended Posts

I'm running into a problem with stretching fields using iReport 3.7.1 on Linux (Ubuntu 9.10).  I have a simple detail band that includes five text fields that are set to stretch.  Except for the Title field, they can be null, set to blank when null, and set not to print when blank. 

Here's the problem.  On records where the Title field is 1 line, preview looks perfect.  When Title stretches to 2 lines, the subsequent field (Journal) also stretches to two lines.  There is extra space where the subsequent stretch fields are positioned, even though they are all blank and no line should be printed.  I've tried adjusting the field height, including 0, and the same happens.  I've included a portion of the detail band including the first four fields.  I also included the entire jrxml and style files for brave souls that take an interest in this problem.  Any thoughts?  Thanks so much!

Code:
<band height="204" splitType="Stretch"><textField>	<reportElement style="Monospace10" x="0" y="0" width="552" height="12" isPrintWhenDetailOverflows="true"/>	<textElement/>	<textFieldExpression class="java.lang.String"><![CDATA[$V{RefType}]]></textFieldExpression></textField><textField isBlankWhenNull="true">	<reportElement style="Monospace10" x="0" y="12" width="552" height="12" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>	<textElement/>	<textFieldExpression class="java.lang.String"><![CDATA[$V{RefYear}]]></textFieldExpression></textField><textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">	<reportElement key="" style="Monospace10" positionType="Float" stretchType="RelativeToBandHeight" x="0" y="24" width="552" height="12" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>	<textElement/>	<textFieldExpression class="java.lang.String"><![CDATA[$V{RefTitle}]]></textFieldExpression></textField><textField isStretchWithOverflow="true" isBlankWhenNull="true">	<reportElement style="Monospace10" positionType="Float" stretchType="RelativeToBandHeight" x="0" y="36" width="552" height="12" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"/>	<textElement/>	<textFieldExpression class="java.lang.String"><![CDATA[$V{RefJournal}]]></textFieldExpression></textField>
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

All the content you put in a band is a line, regardless of its "y" position, i.e. If you put three elements in the detail band:

A: x=0, y=0

B: x=20, y=0

C: x=50, y=20

The three elements are a line in the report, the "C" element is not another line.

If you want to have more control over the layout, you can put the elements in frames (see frame element documentation), If you put the Journal element in a frame, then it will not stretch when another element outside the frame overflows.



Post Edited by asejas at 02/09/2010 20:32



Post Edited by asejas at 02/09/2010 20:32
Link to comment
Share on other sites

asejas, thanks so much for the insight.  I placed my fields in frames and things improved but it wasn't a total fix.  I changed the background color on the frames so I could see exactly what was happening.  If the Title field (enclosed in a frame) is 1 line, all is well.  If the Title field is 2 or 3 lines, bad things happen.  The "Non Journal Frame" is expanded and printed, and space is added after this frame.  The "Non Journal Frame" contains three null fields and should not print.  The space added after this frame shouldn't happen at all, of course.  I tried setting a "print when" condition for the "Non Journal Frame" and it didn't help.  I'm surprised at the problem, because JasperReports is pretty sophisticated and mature, and this seems like a simple thing to do.  I tried setting a "print when" condition for the "Non Journal Frame" and it didn't help. 

Any additional thoughts would be welcomed.  The jrxml file is attached.

Link to comment
Share on other sites

I've found the solution and, since others have viewed this thread, thought it would be helpful to post it here.  Frames do allow grouping of fields and some control of stretch behavior, but there is an easier and more effective way.  The 2007 "Definitive Guide" mentions that elementGroup is specifically used to control stretch behavior.  This feature allows grouping one or more variables, it can be nested, and it is easy to use.  I was able to try a couple of different grouping strategies and got rid of the extra spaces in my report.  So, that's the fix!

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...