Skip to main content

Post 4: iReport: Creating and sizing the title for your report



Creating and sizing the title for your report
A self-explanatory title for your report helps identify the report among other reports. A popular style of designing self-explanatory titles is to have a main title and a subtitle. The main title is normally brief and the subtitle is a more elaborate form of the main title.

In this recipe, you will learn how to provide a main title and a subtitle for your business report. We are going to create, size, position, and color the title.

Getting ready
There is no database connection required in this recipe.
 
If you have not made any database connection so far in your iReport installation, you will see an Empty datasource selected in a drop-down list just below the main iReport menu. This is the requirement to run this recipe. If any other option (for example, some database connection) is previously selected, then change it to Empty datasource from the drop-down list, as follows:


How to do it...
The following steps are very simple, and demonstrate how you can design a basic title for your report:

1. Create the ASimpleTitle.jrxml file of Blank A4 Size . The Designer tab of iReport will show a blank report in the Designer tab of its main window. You can see various sections of your report. The first section at the top of the report is Title, which is a placeholder for the title of your report. 



2. Now you will insert a title into your report. A palette of components is available on the right of the main iReport window. Select the Static Text component from the palette and drag it into the Title section in the Designer tab. 




 3. Double-click and edit the Static Text component to provide a title for your report (for example "Monthly Customer Invoices").



4. You will see that some of the title text will disappear from view. This is because your title is bigger than the standard rectangular boundary of the static text component, which contains the title. So, enlarge the rectangle boundary of this component by dragging one of its corners.
 

5. Now you will give your title a prominent look by increasing its font size. Select the title; the properties of the title field will appear in the Properties window just below the palette of components. Find the Size property among the Text properties and set it to 24.

 

6. Similarly, find the Font property and set it to Verdana, as shown next: 



7. Your report title will get a bold prominent look, as shown here:




8. You can see from the previous image that the title is not well positioned within the Title section. In order to position the title, right-click on the main title, and a pop-up menu will appear; select Position, and another pop up will appear; select Center Horizontally. This will center your title horizontally in the Title section.
 



9. Next, you insert a subtitle for your report by dragging another static text component from the palette into the Title section of your report and repeating steps 2, 3, and 4. I have provided a self-explanatory subtitle "All invoices for a specific customer, in a specific period of time and for a specific product."

10. Now, repeat step 5 for the subtitle and choose 13 as the font size.

11. Switch to the Preview tab, which shows what your report looks like. 



12. You have successfully designed the title of your report. Save it by selecting Save from the File menu.

How it works...
Switch to the XML tab and you will see the following JRXML code:

 <?xml version="1.0" encoding="UTF-8"?>  
 <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ASimpleTitle" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a9528799-f815-4590-885a-c1f169a2b5c2">  
      <property name="ireport.zoom" value="1.0"/>  
      <property name="ireport.x" value="0"/>  
      <property name="ireport.y" value="0"/>  
      <background>  
           <band splitType="Stretch"/>  
      </background>  
      <title>  
           <band height="79" splitType="Stretch">  
                <staticText>  
                     <reportElement uuid="61c08b09-9b8b-437a-bf37-31d2b72071b0" x="107" y="28" width="340" height="35"/>  
                     <textElement>  
                          <font fontName="Verdana" size="24"/>  
                     </textElement>  
                     <text><![CDATA[Monthly Customer Invoice]]></text>  
                </staticText>  
                <staticText>  
                     <reportElement uuid="fdabd8ba-d1ba-43c2-9908-2f6b4f55336d" x="5" y="59" width="545" height="20"/>  
                     <textElement>  
                          <font fontName="Verdana" size="13"/>  
                     </textElement>  
                     <text><![CDATA[All invoices for a specific customer, in a specific period of time and for a specific product]]></text>  
                </staticText>  
           </band>  
      </title>  
      <pageHeader>  
           <band height="35" splitType="Stretch"/>  
      </pageHeader>  
      <columnHeader>  
           <band height="61" splitType="Stretch"/>  
      </columnHeader>  
      <detail>  
           <band height="125" splitType="Stretch"/>  
      </detail>  
      <columnFooter>  
           <band height="45" splitType="Stretch"/>  
      </columnFooter>  
      <pageFooter>  
           <band height="54" splitType="Stretch"/>  
      </pageFooter>  
      <summary>  
           <band height="42" splitType="Stretch"/>  
      </summary>  
 </jasperReport> 


The <title> tag is a wrapper for both of the static text components you dropped into the Title section of your report. Each static text component is represented by a <staticText> child tag of the <title> tag. The first child of the <staticText> tag is named <reportElement>. A <reportElement> tag describes the position (using x and y attributes) and dimensions (using height and width attributes) of the static text component.
 

The x and y attributes control the position of a component. Both of these represent the positioning of the component with respect to the top-left corner of the Title section. You can play around by changing the value of the x and y attributes of the first <reportElement> tag to 0 in the JRXML code. The Designer tab will show that the main title of your report will move to the top-left corner of the Title section.
 

When you centered your main title horizontally in step 8 of this recipe, iReport calculated the values of these x and y attributes for you. This just shows the usefulness of iReport as a graphical report editor.

The height and width attributes control the size of a component. You can also play with these attributes to change the size of your title and subtitle.


The second child, <textElement>, of the <staticText> tag contains a <font> tag, which carries the text formatting information (for example, the name and size of font). You will notice that the <font> tag in the second <textElement> does not have the fontName attribute. That is because you did not change the font property of your subtitle. This means that the subtitle uses the default font, which is SansSerif.

You can see that the title (Monthly Customer Invoices) and subtitle (All invoices for a specific customer, in a specific period of time and for a specific product) of your report are wrapped inside two <text> tags, which go inside <staticText> tags. This means that whenever you drop a static text into the Title section of your report, iReport simply inserts a <staticText> child tag in the <title> tag of your report. Later, when you type the actual title, iReport simply wraps it in the <text> child tag of the <staticText> tag.

You can try editing the title directly from your JRXML. You will see that manual edits in the JRXML are reflected in the designer view of your report.


There's more...
You can also play with the x, y, height, and width attributes from the Designer tab by changing the properties of your main title and subtitle. The x attribute appears as the Left property shown in the Properties window just below the palette of components. Similarly, the y attribute appears as the Top property. The height and width attributes appear as properties with the same name.

Aligning multiple components simultaneously
iReport also allows you to align two or more JasperReports components with respect to each other in your report. For example, you may like aligning the subtitle parallel to the main title. In order to do this, you simply follow the following steps:


1. Open the ASimpleTitle.jrxml file. The Designer tab of the iReport shows that the report contains a title and a subtitle.


2. Hold down the Ctrl key of your keyboard. First, click on the subtitle, which is a reference for you to set alignment of the target component (that is the main title). Secondly, click on the main title and release the Ctrl key. You will see that now both components are viewed as selected.



3. Right-click on any of the components, and a pop-up menu will appear; select Align, and another pop up will appear; select Align Left.



This will align the main title with the subtitle, as shown next:
 

Tips: Sometimes, it is difficult to drag to a specific width. It is better to enter the width in the XML View. For example, it is difficult to drag the width from 58 to 60. Instead of struggling with the mouse, it is better to enter 60.

Comments

Popular posts from this blog

TIME TABLE: VTU BE/B.Tech June/July 2016 Exam Time table Draft Layout

Semester-wise June-July 2016 Exam time table (Draft Layout) Are You Using updated Kwikstudy App?

Walkins Bangalore: 01st-Oct-2016

1. UTC Aerospace : GET – S&IS-Software Team hiring Electronics & CSE / IT Freshers ! Walkin on 1st OCT | BE/BTECH - 2015 & 2016 both batch can try Selection Process : Written Test Group Discussion Technical & HR Interviews How To Apply : It is a walk-in drive for 2016 batch eligible freshers on 1 Oct 2016 at Bangalore location. Interested and eligible candidates can walk-in to the following venue on 1 Oct 2016 Date of Drive : 01 Oct 2016 Reporting Time : 8:00 AM to 11:30 AM Venue : UTC Aerospace Systems – Site 1, Sy. Nos. 14/1 & 15/1, Maruthi Industrial State, Phase 2, Hoody Village, Whitefield Road, K R Puram Hobli, Bangalore – 560048 ______________________________________ 2. HP : Software Eng/ Software Tester (Call based ,less chance of getting entry , try at your own risk) Event Date : 1-October-2016 Event Time : 8 : 00 am Job Location : Bangalore / Chennai Job Description: Software Engineer /

How to get VTU Provisional Degree Certificate (PDC) ?

Here is the procedure to get the Provisional Degree Certificate from the VTU by passed out candidates. You can get the certificate through post by sending the required documents to VTU. Documents and things required: 1. Provisional Degree Certificate (PDC) application form 2. DD of specified fees amount or print copy of receipt if you paid the fees online 3. A letter to the VTU registrar 4. A4 size envelope Step 1: Fill the PDC application You can download the PDC application form from the VTU website. Click below link for application download. PDC application form download     After downloading the application take a print of it and properly fill the form. Step 2: Make a DD of specified amount as the fees of PDC: Go to the bank and make the DD of prescribed fee amount for the PDC. The fee amount is specified in the above link from where you downloaded the application. Make the DD in favor of " Finance Officer, VTU Belgaum ".   Wr