Tom Sebastian
Tom Sebastian

Reputation: 3433

How to specify different background colors for alternative rows programatically with JasperReports API

I am creating JasperReports xls report with Java code (without using .jrxml).

I need to set different background colors for alternative rows in detail section.

How can i do it?

Upvotes: 0

Views: 981

Answers (1)

MrD
MrD

Reputation: 1275

Use a style-definition at the beginning of your report:

<style name="DataCellStyle" mode="Opaque" border="None">
  <conditionalStyle>
    <conditionExpression>
      <![CDATA[new Boolean($V{REPORT_COUNT}.intValue() % 2 == 0)]]>
    </conditionExpression>
    <style mode="Opaque" backcolor="#E0E0E0" />
  </conditionalStyle>
</style>

...and use this style for your data-cells:

<detail>
  <band height="15">
    <textField>
      <reportElement x="0" y="0" width="150" height="15" style="DataCellStyle"/>
      <textFieldExpression class="java.lang.String">
        <!-- something -->
      </textFieldExpression>
    </textField>
  </band>
</detail>

More info about conditional styles is here

Upvotes: 1

Related Questions