Dynamic color in TextField in Jasper reports

0

I want to change the color of the textfield according to the value of it, I found several tutorials that say to create a style and apply to the textfield, have to select a "styled text" option that I did not find in the textfield properties in jasper, the tutorials all refer to Ireport and I use JasperReports, any tips?

    
asked by anonymous 10.09.2015 / 17:49

2 answers

0

If you can not find it, another possible solution is to overlay another textfield with the color you want and switch to show one or the other:

    
10.09.2015 / 19:09
1

I've been through this same problem, I needed to paint each line of the red report pair, so I found the following solution:

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

Here in this section I create the Style that has a Boolean condition:

(if the counter number of the line divided by 2 is = 0 then it is a even line and its background will be red)

new Boolean($V{REPORT_COUNT}.intValue() %2 == 0)

After creating this style with the name = style_background I add it to the style attribute of textField:

<textField>
    <reportElement style="style_fundo_vermelho" x="658" y="1" width="90" height="16" uuid="c118ccc6-4074-4f03-9bfa-cf6c3ae8a1b9">
    </reportElement>    
</textField>

So you can solve your dynamic background color problem in text field by simply adapting style to your need.

    
22.05.2017 / 20:19