Alternate Background colour of rows in JasperReport
Use conditional style.
A conditional style has two elements: a Boolean condition expression and a style. The
style is used only if the condition evaluates to true.
We have following code snippet to get alternating row color.
<style name="alternateStyle" fontName="Arial" backcolor="red">
<conditionalStyle>
<conditionExpression>
new Boolean($V{REPORT_COUNT}.intValue() % 2 == 0)
</conditionExpression>
<style backcolor="blue"/>
</conditionalStyle>
</style>
In this example, element with this style will get red backcolor. But the presence of conditional style changes the behaviour and when rendered on an even row, the same element will have blue backcolor.
A conditional style override the properties of parent style.
OR
just put the a rectangle with a different background color and set the printwhenexpression to :
new Boolean(($V{REPORT_COUNT} mod 2) == 0)
In the Detail section make sure all the existing elements are set to Transparent.
Now in the Detail section of your report create a new Static Text box. Size it to cover the full extents of the detail section. If you are using multiple columns size it to the full extent of just one column. Set its background colour to be whatever you want it to be. Put a single space in the Static Text area.
To make it toggle on and off you use a Print When expression based on your BACKGROUND variable. Set it to be new java.lang.Boolean(($V{BACKGROUND}.intValue() % 2)==1)
Now all you need to do is send it to the back. Under the Format Menu choose the Send to Back option, and your done.