问题
I have a field which displays "To : NAME". Here "To" is static and "NAME" is a variable. So I have used a single Text Field attr and "To: " + $F{name} as an expression. Now, the problem is, I have to use two separate fonts for "To" and "Name". I've tried using style but I must be missing something. Could you please help me out?
N.B : I cannot use static text for "To" and text field for "name" field as horizontal alignment for these has to be center being together.
回答1:
ok, I'm able to achieve this modifying the jasper xml in the following way -->
<textField>
<reportElement x="36" y="192" width="329" height="16"/>
<textElement textAlignment="Center" verticalAlignment="Middle" markup="styled">
<font size="10"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA["<style fontName='ChronicleTextG1_Italic'>To: </style><style fontName='ChronicleTextG1_Roman'>" + $F{TO_NAME} + "</style>"]]></textFieldExpression>
</textField>
Hope it helps other.
回答2:
You just can do this within the iReport expression editor without the need for manually editing the jrxml.
For HTML markup, this looks like so within the expression editor (set font 'ChronicleTextG1_Italic' directly on the field as usual. This will take care of the font for 'To:'):
"To: <font face='ChronicleTextG1_Roman'>" + $F{TO_NAME} + "</font>"
来源:https://stackoverflow.com/questions/16294372/use-multiple-fonts-for-a-single-text-field-in-jasper-reports