Java Reference
In-Depth Information
Setting the Size and Position of a Report
Element
The x and y attributes of <reportElement> specify the x and y coordinates (in
pixels) of the element within the band. An initial common mistake is to assume that
the x and y coordinates, which are defined here, are absolute for the page. Again,
the x and y coordinates, defined by the x and y attributes, are relative to the <band>
where the element is contained. Coordinates (0, 0) are at the top left of the band. The
x and y attributes of <reportElement> are required.
The width and height elements of <reportElement> , unsurprisingly, define the
width and height (in pixels) of the element, respectively. The width and height
attributes of <reportElement> are required. We have already seen several examples
demonstrating the use of the x , y , width , and height elements of <reportElement> .
Here is the JRXML template for the report we created in Chapter 3:
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="FirstReport">
<detail>
<band height="20">
<staticText>
<reportElement x="20" y="0" width="200" height="20"/>
<text><![CDATA[If you don't see this, it didn't work]]></text>
</staticText>
</band>
</detail>
</jasperReport>
In this example, the static text will appear 20 pixels from the left margin, aligned with
the top of the band. Refer to Chapter 3 to see a rendered report based on this template.
The positionType attribute defines the element's position when the band is
stretched. As can be seen in the table overleaf, there are three legal values for this
attribute, namely, Float , FixRelativeToTop , and FixRelativeToBottom . Let us
modify the example we showed in the Allowing Text Fields to Stretch to Accommodate
their Data section by adding some static text right under the existing text field. We
will see the effect the different positionType values have on its positioning.
 
Search WWH ::




Custom Search