How to change to background color of textfield Dynamically in iReport using Java

6k Views Asked by At

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.

2

There are 2 best solutions below

3
On BEST ANSWER

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.

2
On
   <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>