I want to change the background color of my text field based on a variable.
Here's the logic:
if (variable <= 20) then
text field color = red
else if (variable > 20) then
text field color = green
end if
Something like that.
<style name="alternateStyle" fontName="Arial">
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{SANCTION_AMOUNT_MEASURE}.intValue() <= 20)]]></conditionExpression>
<style mode="Opaque" backcolor="#FF0000" isBold="true"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{SANCTION_AMOUNT_MEASURE}.intValue() > 20)]]></conditionExpression>
<style mode="Opaque" backcolor="#00FF00" isBold="true"/>
</conditionalStyle>
</style>
Usually the way to do that its using a conditional style: You have to create a new style:
https://community.jaspersoft.com/questions/825330/how-create-conditional-style-jaspersoft-studio
put the condition in the style and apply the style to your textfield.