Search code examples
jasper-reportsjaspersoft-studio

How to create dynamic color for text field?


Background: Jaspersoft studio 6.2

How to change forecolor of a text field based on an expression.

How can I apply a expression so the font color (forecolor) will be based on the value in that field? I can't find anywhere to set a expression for the forecolor property.


Solution

  • Maybe there is an option:

    You need to set markup to style. And then use an expression in the text field:

    F{value1}=="GREEN"?$F{value1}:"<style backcolor='red'>"+$F{value1}+"</style>"
    

    You can also add conditions and set multiple colors:

    F{value1}=="GREEN"?"<style backcolor='green'>"+$F{value1}+"</style>":"<style backcolor='red'>"+$F{value1}+"</style>"
    

    Maybe this will work for you.