Change font size to fit text field

Is there a way to change the font size of a text field based on the number of charachters and the field width ? This is for labels and there is no room to stretch the field. I was thinking about some inline java that would count the number of charachters and spit out the right font size in the size attribute. 

<font fontName="Arial" size=(inline java goes here somehow) isBold="true"/>

I can write the java expression. I am not sure how to place the inline java in the attribute.

Other suggestions are welcomed.

Thanks,

Warren

warrenbell2's picture
Joined: Dec 28 2014 - 4:05pm
Last seen: 6 years 4 months ago

1 Answer:

i think you can use the conditional expressions and find out the length of a string field and assign font size to it.

In the below style, I'm checking for the length of the field.

  1. Assign Font size 14 if length is less than 10 characters
  2. Assign Font size 11/Bold if length is greater than 10 characters

 

    <style name="conditional">
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{ID}.length() < 10 ? true : false]]></conditionExpression>
            <style fontSize="14"/>
        </conditionalStyle>
        <conditionalStyle>
            <conditionExpression><![CDATA[$F{ID}.length() > 10 ? true : false]]></conditionExpression>
            <style fontSize="11" isBold="true"/>
        </conditionalStyle>
    </style>

 

reportdev's picture
12902
Joined: Oct 12 2015 - 12:05pm
Last seen: 1 year 3 months ago
Feedback
randomness