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
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.
- Assign Font size 14 if length is less than 10 characters
- 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>