Background color textfield depending on field value

Hi there!

I have a problem with dynamic background color of textfield based on the value of field. I have the following textfields:





I have a style:

<style name="Color">
     <conditionExpression><![CDATA[$F{number1} == 1]]></conditionExpression>
    <style mode="Opaque" backcolor="red"/>
     <conditionExpression><![CDATA[$F{number1} == 2]]></conditionExpression>
    <style mode="Opaque" backcolor="black"/>

The style 'Color' works for the textfield with field $F{number1}, but, I need apply that conditionExpression to others textfields(and every one have a different field associated), but I dont want duplicate the style for every field.

Thanks for advance!!

(I'm sorry for my bad english, if it's not clear please tell me)

camilo.rodriguez17's picture
Joined: Jan 27 2014 - 10:36am
Last seen: 9 years 3 months ago

1 Answer:


In order to achieve this scenario the most feasible method is what you have stated in you rquertion itself, that is creating several conditional styles, and it is not duplicating the styles, but if you are using iReport/Jaspersoft studio, then you can see that a single style can have several condional styling options so you need to apply only one style to all the textfeilds in the report and that will cater you needs according to the conditions.


Hope that this helps,

Ankur Gupta

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 1 week 18 hours ago

Ankurt thanks for your answer. I understand that you say, but if I apply the unique style with multiples "conditionalStyle", and apply the same style to every field(suppose that I have 80 fields), the generation time of the report will be higher? (I think so because the evaluation of every conditionalStyle take more time, but I'm not sure I'm a newbie with jasper)

I see other software and I show that: BIRT or Reporting Services of Microsoft have the posibility to include my requeriment more faster and easy. :( .. thanks again for your help!

camilo.rodriguez17 - 9 years 8 months ago

Ankur missed the point of the question

dunham - 5 years 5 months ago

Please enlighten us with your take on the question, so that it helps the community!!

Ankur Gupta - 5 years 5 months ago