Monday, 13 November 2017

iReport Dynamically changing font size

Today I will show you how to dynamically change font size in jasper reports using iReport designer tool. To change font size dynamically we need to create two variables, and give a readable name to that variables. To create variables follow these steps.

1- Go to your Report Inspector tab
2- Expand Variables
3- Right click on Variables and select Add Variables

4- After adding variable give a readable name to variable and set variable expression to that variable.

5- Revise above steps for second variable with different variable name. Now that you have two variables. Now we use that variable with different fonts in our report using "Print When Expression" property. In this property we find length of variable expression  which we have given in step no 4.

Print When Expression

Print this statement when this expression is true.

6- Now click on "Print When Expression" property and type following code.

($F{you_field_name}.length() > 28)&&($F{you_field_name}.length())

In the above code we have checked that if the field length is greater than 28 then print this field other wise hide this field. Similarly we can do this with other field. Now we have two fields and we can easily set font size on that field. Means if the length of fields meets above condition than print those with field value with your desired font size otherwise display another field with different font size.