How to create dynamic color for text field?

thotwielder picture thotwielder · Apr 21, 2016 · Viewed 14.3k times · Source

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.

Answer

shertage picture shertage · Jul 6, 2016

Another possibility would be to use a style property expression in your textfield:

<textField ...>
  <reportElement ...>
      <propertyExpression name="net.sf.jasperreports.style.forecolor">
         <![CDATA["#00FF00"]]>
      </propertyExpression>
  </reportElement>
  ...
</textField>

This setting will override the current forecolor attribute for the textfield, and a green text will be printed out.

Here are listed all dynamic style properties available for report elements.