Tutorial Four: How to create a very simple subreport
In this tutorial we will see how to create and compile a simple subreport using iReport
Step1: creation of the master report
1) Open the Wizard tool and create a new columnar report
2) We will select all states stored in ours database using a query like: select * from states order by name
3) ...we will use all fileds, incluse "state_id"
3) No group selected in the next step...
4) We choose a classic columar report as template"
5) Save report as master.xml (or foo.xml or bar.xml or ...)
Step2: compile and preview master
1) Save the new magically created report, compile and preview it.
2) All OK? Very good.
3) Create some space between the last field and the pageFooter dragging pageFooter line.
4) Add a subreport element.
5) Open subreport properties (double-click on subreport element) and set left = 0 and width = 535. With this
values the subreport will use all available horizontal space. Set position type to float: position float means that
the position of the subreport element can be adapted vertically to the requirements of the report, moving itself.
There is not a flag like "isStretchWithOverflow" because it is implicit for subreport elements.
Step3: creating the child subreport
1) Follow the same instructions at step 1 for create a tabular report...
2) We will create this time a tabular report selecting cities with a query like: select * from cities order by state_id,name
3) Now we must make some modification: delete title and page numbers
4) Select menu View->Report properties to open the report properties window. Set all margins to 0 and report width to 535 (the same width of
the subreport element created in teh master report)
5) You now must work a bit to adjust all element, changing margin could be have strange effect to the report ;-)
6) At the end you should have something like what you see in the last screenshot of this step.
7) Save report as child.xml (or foo_child.xml or barxxx.xml or ...)
8) If you want, you can try to compile and preview it...
Now, you are ready to compiling JasperReports samples