Jump to content
We've recently updated our Privacy Statement, available here ×

Conditionally change font in textfield?


someguy51

Recommended Posts

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Yes it is but you need two text fields. One should be set for one font, the other set for the other font. Both text fields will occupy the same space on the report. Set the print when expression for both text fields to be based on the flag settings. ex. flag == true. This way when the report is run the correct font will print based on the condition.
Link to comment
Share on other sites

someguy51 wrote:

Hi,

Is it possible to conditionally change the font in a textfield? For example, I want to bold a textfield when a flag is true and have the same textfield not bolded when the flag is false.

Thanks

 

You don't need to have 2 textfields for this.

Just use the condtional expression in the textfields expression. This expression changes the current style if deger1 paramater is equal to isim field. I hope it helps.

 

Code:
($F{isim}.equals($P{deger1}) ? 
"<style isBold='TRUE' forecolor='red' size='20' pdfFontName='Helvetica-Bold'>"
+$F{isim}+"</style>"
: $F{isim} )
Link to comment
Share on other sites

Hi SoS,

 

Thanks for your reply. It would be more convienient to use only one textfield so I tried your idea.

 

Here is my code in the textfield expression:

 

Code:

(SL2.isReminderAlarm($F{reminddaysn}, $F{receivedon}, $F{remindon}).booleanValue()) ?
"<style isBold='TRUE' pdfFontName='Helvetica-Bold'>" + $F{typedtq} + "</style>"
: $F{typedtq}

 

When "isReminderAlarm" returned false it just printed "typedtq" as expected. However, when it returned true it actually printed the text "<style..." instead of changing the font.

 

Perhaps the version we are using is too old? It is iReports 1.2.3

 

Any ideas?

 

Thanks,

someguy51

Link to comment
Share on other sites

i first used it with 1.2.4 (both jasper & ireport) and now i m using with 1.2.5 with no problem at all. HTML & PDF exports were ok. As you wrote, you might try some newer versions i guess.

 

Also check if you enabled StyledText option for that textfield element. :side:

Post edited by: SoS, at: 2006/07/28 06:19

Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...