Java Reference
In-Depth Information
Setting Text Style for Individual Report Elements
Report styles can be shared among several report elements. By setting attributes in
the
<textElement>
sub-element of
<staticText>
and
<textField>
, JasperReports
allows us to set some properties for individual report elements. These attributes are
outlined in the following table:
Attribute
Description
Valid Values
lineSpacing
Determines the spacing
between lines of text. A value
of
1_1_2
indicates a line and
a half of space between lines
of text.
1_1_2
,
Double
,
Single
rotation
Indicates the text direction by
rotating it 90 degrees in the
specified direction.
Left
,
None
,
Right
textAlignment
Indicates the horizontal
alignment of the text.
Center
,
Justified
,
Left
,
Right
verticalAlignment
Indicates the vertical
alignment of the text.
Bottom
,
Middle
,
Top
isStyledText
Indicates whether the element
text is styled.
true
,
false
The following snippet of a JRXML template illustrates how to use these attributes:
<staticText>
<reportElement x="0" y="0" width="555" height="30"/>
<textElement lineSpacing="Double" textAlignment="center"
verticalAlignment="Middle"/>
<text>
<![CDATA[This text is not really important.]]>
</text>
</staticText>
This snippet would generate text using double spacing, horizontally, and vertically
centered. The
<textElement>
element is a sub-element of both
<staticText>
and
<textField>
.
Use Styles to Create More Maintainable Reports
It is usually faster to set the text properties using the
<textElement>
element. However, doing it this way prevents
us from reusing the styles across several elements. Report styles
allow us to do this, and they provide much more control than
the attributes in
<textElement>
.