Configuring and Formatting iReport Elements

Exclusive offer: get 50% off this eBook here
iReport 3.7

iReport 3.7 — Save 50%

Learn how to use iReport to create, design, format, and export reports

$23.99    $12.00
by Shamsuddin Ahammad | March 2010 | Java Open Source

In this article by Shamsuddin Ahammad, author of iReport 3.7, we will cover:

  • Understanding bands
  • Configuring and using report bands
  • Maintaining the size, position, and alignment of the report elements
  • Modifying report fonts
  • Using the library
  • Using borders
  • Modifying element properties

This article is a follow up of the article Setting Up the iReport Pages.

A complete report is structured by composing a set of sections called bands. Each band has its own configurable height, a particular position in the structure, and is used for a particular objective. The available bands are: Title, Page Header, Column Header, Detail 1, Column Footer, Page Footer, Last Footer, and Summary.

A report structured with bands is shown in the following screenshot:

iReport 3.7

Besides the mentioned bands, there are two special bands which are Background and No Data.

Band

Description

Title

Is the first band of the report and is printed only once. Title can be shown on a new page. You can configure this from the report properties discussed in the previous section of this chapter. Just to review-go to report Properties | More... and check the Title on a new page checkbox.

Page Header

Is printed on each page of the report and is used for setting up the page header.

Column Header

Is printed on each page, if there is a detail band on that page. This band is used for the column heading.

Detail

This band is repeatedly printed for each row in the data source. In the List of Products report, it is printed for each product record.

Column Footer

Is printed on each page if there is a detail band on that page. This band is used for the column heading. If the Floating column footer in report Properties is checked, then the column footer will be shown just below the last data of the column, otherwise it will be shown at the bottom of the page (above the page footer).

Page Footer

Is printed on each page except the last page, if Last Page Footer is set. If Last Page Footer is not set, then it is printed on the last page also. This band is a good place to insert page numbers.

Last Page Footer

Is printed only on the last page as a page footer.

Summary

Is printed only once at the end of the report. It can be printed on a separate page if it is configured from the report Properties. In the following chapters, we will produce some reports where you will learn about the suitability of this band.

Background

Is used for setting a page background. For example, we may want a watermark image for the report pages.

No Data

When no data is available for the reports, this band is printed if it is set as the When no data option in the report Properties.

Showing/hiding bands and inserting elements

Now, we are going to configure the report bands (setting height, visibility, and so on) and format the report elements.

  1. Select Column Footer from the Report Inspector. You will see the Column Footer - Properties on the right of the designer.
  2. Type 25 in the Band height field.
  3. iReport 3.7

  4. Press Enter. Now you can see the Column Footer band in your report, which was invisible before you set the band height.
  5. A band becomes invisible in the report if its height is set to zero. We have already learned how to change the height of a band. We can also make a band invisible using the Print When Expression option. If we write new Boolean(false) in Print When Expression of a band, then that will make the band invisible, even though its height is set to greater than zero. If we write new Boolean(true), then the band will be visible. It is true by default.

  6. Drag a Static Text element from the Palette window and drop it on the Column Footer band. Double-click on Static Text and type End of Record, replacing the text Static Text.
  7. iReport 3.7

  8. Select the static text element (End of Record). Go to Format | Position and then choose Center. Now the element has been positioned in the center of the Column Footer band.
  9. In the same way, insert two Line elements. Place one element at the left and another at the right of the static text.
  10. Select both the lines. Go to Format | Position, and then choose Center Vertically . The lines are now positioned in the center of the Column Footer vertically.
  11. Select both the lines and go to Format | Size and then choose Same Width. Now both the lines are equal in width.
  12. Select the static text element (End of Record) and the left line. Now go to Format | Position and choose Join Sides Right. This moves the line to the right, and it is now connected to the static text element.
  13. Repeat the previous step for the right line and finally choose Join Sides Left. Now the line has moved to the left and is connected with the static text element.
  14. In the same way, change the column headers as you want by double-clicking the labels on the Column Header band. Now, the columns may be Product Code, Name, and Description.
  15. Now your report design should look like the following screenshot:
  16. iReport 3.7

  17. Preview the report, and you will see the lines and static text (End of Record) at the bottom of the column.

By default, the Column Footer is placed at the bottom of the page. To show the Column Footer just below the table of data, the Float column footer option must be enabled from the report Properties window.

iReport 3.7

Sizing elements

We can increase or decrease the size of an element by dragging the mouse accordingly. Sometimes, we need to set the size of an element automatically based on other elements' sizes. There are various options for setting the automatic size of an element. These options are available in the format menu (Format | Size).

Size Options

Description

Same Width

This makes the selected elements of the same width. The width of the element that you select first is used as the new width of the selected elements.

Same Width (max)

The width of the largest of the selected elements is set as the width of all the selected elements.

Same Width (min)

The width of the smallest of the selected elements is set as the width of all the selected elements.

Same Height

This makes the selected elements of the same height. The height of the element that you select first is used as the new height of the selected elements.

Same Height (max)

The height of the largest of the selected elements is set as the height of all the selected elements.

Same Height (min)

The height of the smallest of the selected elements is set as the height of all the selected elements.

Same Size

Both the width and the height of the selected elements become the same.

Position

Description

Center Horizontally (band/cell based)

The selected element is placed in the center of the band horizontally.

Center Vertically (band/cell based)

The selected element is placed in the center of the band vertically.

Center (in band/cell)

The selected element is placed in the center of the band both horizontally and vertically.

Center (in background)

If the Background band is visible and if the element is on the Background band, then it will be placed in the center both horizontally and vertically.

Join Left

Joins two elements. For joining, one element will be moved to the left.

Join Right

Joins two elements. For joining, one element will be moved to the right.

Align to Left Margin

The selected element will be joined with the left margin of the report.

Align to Right Margin

The selected element will be joined with the right margin of the report.

iReport 3.7 Learn how to use iReport to create, design, format, and export reports
Published: April 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

Positioning elements

We can change the position of elements easily by using the drag-and-drop feature. However, for automatic positioning of an element based on bands/cell or other elements, we can use the options in Format | Position.

Handling null values

In the report, you can see a null value for Description of RAM. This is because in the database this field is null. To display a blank when it is null in the database, select all the fields ($F{ProductCode}, $F{Name}, $F{Description}), and then check Blank when null from the Multiple Objects - Properties.

iReport 3.7

Now, the report output will be as shown in the following screenshot (Description of RAM is blank):

iReport 3.7

Font settings

We will now change the report font for the data elements. Select all the fields, find Font name from Properties, and choose Times New Roman as Font name, and 12 as Size.

iReport 3.7

Creating text field pattern

In the Page Footer band, you can see the current date and the page numbers, as shown in the following screenshot:

iReport 3.7

We will modify the elements of Page Footer now. To change the date format, select date element (new java.util.Date()), go to Properties | Text Field Properties, and see the Pattern.

iReport 3.7

Now, follow the steps listed to change the date pattern:

  1. Open the pattern editor by clicking the button next to Pattern.
  2. Select Date from Category.
  3. Select dd/MM/yyyy h.mm a from the Type window.
  4. iReport 3.7

  5. Press OK. The date pattern is changed to the output, as shown in the following screenshot:

iReport 3.7

Setting borders

Now we will set borders for the field elements in some easy steps:

  1. Select all fields.
  2. Right-click and select Padding and Borders.
  3. iReport 3.7

  4. Set the Left, Right, Top, and Bottom Padding as 1.
  5. Set 1 as the Line width.
  6. Select Line color.
  7. Press OK.
  8. Preview the report to see the output, as shown in the following screenshot:

iReport 3.7

Using tools for current date and inserting page numbers

Current date and page numbers are automatically set on the Page Footer band, if the report is created from the wizard. However, to add these manually to the report, we can use built-in tools in the Palette.

From the library options, drag the Page X of Y to the Page Footer band of your report, where you want to show the page numbers. Again, drag the Current Date in the same way.

Summary

We learned a lot in this article about formatting the report and its elements.

Specifically, we covered:

  • Bands
  • Setting the size of elements
  • Setting the position of elements
  • Setting the pattern for fields
  • Setting the fonts of elements
  • Using the built-in tools
  • Setting the border for the elements

If you have read this article you may be interested to view :

iReport 3.7 Learn how to use iReport to create, design, format, and export reports
Published: April 2010
eBook Price: $23.99
Book Price: $39.99
See more
Select your format and quantity:

About the Author :


Shamsuddin Ahammad

Shamsuddin Ahammad is a Senior Lecturer and the Course Coordinator at Daffodil Institute of IT, Bangladesh. He has been teaching Java, Programming Methods, and Database Systems since 2002. He has experience in supervising hundreds of academic projects. Shamsuddin has a Masters degree in Management Information Systems (MIS) from Daffodil International University, Dhaka. He obtained the BSc(Hons) degree in Computing & Information Systems (CIS) of NCC Education Ltd, UK and London Metropolitan University joint programme from Daffodil Institute of IT. Before that, he completed the IDCS & IADCS of NCC Education Ltd. He is an Additional Reviewer of Conference on Quality Engineering in Software Technology (CONQUEST) organized by International Software Quality Institute (iSQI) in Germany. He is the author of book titled iReport 3.7 published from PACKT Publishing in March 2010.

Books From Packt


jQuery 1.4 Reference Guide
jQuery 1.4 Reference Guide

Getting started with Audacity 1.3
Getting started with Audacity 1.3

MySQL Admin Cookbook
MySQL Admin Cookbook

Apache MyFaces 1.2 Web Application Development
Apache MyFaces 1.2 Web Application Development

Drupal E-commerce with Ubercart 2.x
Drupal E-commerce with Ubercart 2.x

NetBeans Platform 6.8 Developer's Guide
NetBeans Platform 6.8 Developer's Guide

ZK Developer’s Guide
    ZK Developer’s Guide

Joomla! 1.5: Beginner's Guide
Joomla! 1.5: Beginner's Guide


No votes yet
Automatic Width by
Hi, Is there in Ireport an option that allows to have an automatic width (if report is in portrait or paysage for example) ? Tks
its nice by
its nice

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
k
3
D
5
p
9
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software