Expanding a field vertically to accommodate large text

This recipe teaches you how to handle the presentation of dynamic data in text fields, which can contain large amounts of data. Large dynamic text scenarios occur when your report contains sentences, the exact word count of which is not known while designing a report and will be determined during report processing (for example, a sentence that contains the name and address of a company). In such situations, the large text size can overflow the size of the field and, therefore, wrapping to the next line may become essential.

Getting ready

Refer to the installPostgreSQL.txt file included in the source code download for this chapter to install and run PostgreSQL, which should be up and running before you proceed. The source code for this chapter also includes a file named copySampleDataIntoPGS.txt, which helps you create a database named jasperdb3 and copy sample data for this recipe into the database.

How to do it...

  1. Open the VerticalStretch.jrxml file from the Task4 folder in the source code for this chapter. The Designer tab of iReport shows a report, as follows:
    How to do it...
  2. Switch to the Preview tab to see a current preview of your report. You will see a report with bulleted lists of records grouped based upon customer names and product names, forming a nested hierarchy.
    How to do it...
  3. Switch back to the Designer tab. Select the Text Field component in the Detail 1 section. Right-click on it, and a pop-up menu will appear. Select Edit expression from the pop-up menu.
    How to do it...
  4. An Expression editor dialog will appear, as shown in the following screenshot:
    How to do it...
  5. Take your cursor to the beginning of the expression by pressing the Home key on your keyboard. You will notice a<font> tag at the beginning of the expression.
    How to do it...
  6. Change the value of the size parameter of the<font> tag from 13 to 25. Click on the Apply button. The Expression editor will disappear.
  7. Switch to the Preview tab. The report will look as follows:
    How to do it...
  8. Notice that the preview output is not as we expected. The text of the Detail 1 section Text Field is missing in the preview, (We were expecting that the text would appear larger than before.)
  9. This problem is usually faced when we use a smaller text field to display a larger text. To solve this problem JasperReports offers a feature of dynamically stretching a text field with overflow of text. To use this feature, switch back to the Designer tab.
  10. Select the Text Field in the Detail 1 section. Select the Stretch With Overflow property from the Text field properties section of the Properties window below the Palette. Tick the checkbox beside it, as shown in the following screenshot:
    How to do it...
  11. Switch to the Preview tab. The report will look as shown below. Notice that the preview output is now as we expected. The text of the Detail 1 section Text Field is appearing in a very large size in the preview.
    How to do it...

How it works...

This recipe works because JasperReports allows us to use stretchable fields, which it automatically stretches in a vertical fashion when it sees that data in the field cannot be accommodated within one line. If you switch to the XML tab, you will see the following JRXML code for the text field that you made stretchable in this recipe:

<textField isStretchWithOverflow="true">

You can see the isStretchWithOverflow="true" attribute in the<textField> tag. This attribute makes your text fields stretchable. iReport authored this attribute in response to step 9 of this recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.204.0