Bolding part of a text field

1

 Hi, I have a text field that contains some text. I don't want to bold all of it, only part of it.

Here is the xml of the text field:

<textFieldExpression class="java.lang.String"><![CDATA[$R{statementMessage.report.label}+": "+$P{StatementMessage}]]></textFieldExpression>

Here is how I tried to do it:

<textFieldExpression class="java.lang.String"><![CDATA[<style isBold="true" pdfFontName="Helvetica-Bold">$R{statementMessage.report.label}+": "</style>+$P{StatementMessage}]]></textFieldExpression>

Notice the style tags I used. That didn't work. I've tried several other ways but none of them worked. How should I go about doing this?

gbaldeck's picture
Joined: Feb 14 2011 - 6:36am
Last seen: 8 years 11 months ago

are you know if this fix is available to ireport version 3.0.0?

danielro094 - 2 months 3 weeks ago

4 Answers:

3

You are moments away from a solution!  In iReport, instead of setting your expression to:

$R{statementMessage.report.label } + ": " + $P{StatementMessage}

scroll all the way down the properties screen for that field and change the "Markup" property from "None" to "Styled" and then change the expression for this field to read:

"<style isBold=\\"true\\">" + $R{statementMessage.report.label} + ": </style>" + $P{StatementMessage}

Remember, that's the actual expression you enter in iReport designer mode...you don't have to edit the jrxml.

But that's just the beginning of what you can do with styled markup.  See the attached jrxml file and execute it (the static text sections look impressive in Design view, but the text fields only work at runtime) to get an idea of the possibilities.  This example is slightly modified from the one I got from Matt Dahlmann, who I now consider the undisputed king of styled text knowledge (and he's also extremely helpful on this forum in other areas).

Carl

cbarlow3's picture
1470
Joined: Mar 4 2010 - 8:59am
Last seen: 2 months 1 week ago
0

 That worked! The file you attached looks like a huge help too. Thank you.

gbaldeck's picture
Joined: Feb 14 2011 - 6:36am
Last seen: 8 years 11 months ago
2

Is that attachment still available somewhere? I used your isBold suggestion and it worked perfectly! (Only change was escaping the "true" quotes with one forwardslash not two).

If you have the attachment still, that would be awesome.

Thanks

simon_tsa's picture
Joined: Sep 22 2013 - 11:46pm
Last seen: 1 year 2 months ago
0

I would also love to have that attachment. I can't see it.

martin.torre.castro's picture
Joined: Sep 13 2016 - 7:52am
Last seen: 3 years 4 months ago
Feedback