Dynamic Color in Textfield in Jasper Reports

Asked

Viewed 1,096 times

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 textfield, you have to mark a "Styled text" option that I did not find in the properties of textfield in Jasper, the tutorials all refer to Ireport and I use Jasperreports, some tip?

  • Hello Julio, could you post one mvce with an example report, the call to generate it and the point at which you want to apply the style dynamically?

2 answers

1

I already went through this same problem, I needed to paint each line of the report pair red, so I found following the 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 line counter number divided by 2 is = 0 then it is an even line and its background will be red)

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

after creating this style with the name= style_botto_red 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 already solve your dynamic background color problem in text field, just adapt to style for your need.

0


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

  • Yeah, I didn’t want to use this but it’s gonna be the way! Kkkkkkkkkkkkkkkkkkkk Thanks man!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.