Jump to content
Changes to the Jaspersoft community edition download ×

Formatting a textfield depending on content?

2005 IR Help

Recommended Posts

By: eztup - eztup

Formatting a textfield depending on content?

2005-04-06 04:22



I'm using iReport 0.4.1 and need to display positive numbers in a different color than negative (e.g. 12,0% in black and -4,0% in red).

The problem is that you can only assign one color to a textfield. Can I hack this ?) Or is there a possibility like in MS Excel, where you can completely format a cell depending on the content...

I tried to use a parameter which has been filled before in my application - but I don't know the syntax of how to change iReport-xml like this:


<textField isStretchWithOverflow="...>














By: eztup - eztup

RE: Formatting a textfield depending on conte

2005-04-12 06:39

Worxx :) But uhh, this is lame somehow ;) Isn't there an expression for the jasper-xml-file for the corresponding textField-node? With your way it's hard to change a finished report because you must know that there is another layer under the visible fields...





By: C-Box - c-box

RE: Formatting a textfield depending on conte

2005-04-12 08:46

Yes I also think there must something be done... kind of "JRConditionStyle" that is member of JRElement and has a style (for JRTextFields at least ForeGroundColor, BackGroundColor, FontStyle, FontName, FontSize) for several conditions (e.g. new Boolean($F(MyField).equals("BlaBlaBla")) if one of these conditions is returning true, the corresponding style should be used...


So for example you could turn a number field to red when it's negativ, in black when it's between 0 and 100 and in green when it's more than 100.... and have JUST ONE FIELD declared and positioned in design. (It would be great)


I think this would be a very nice feature Jasper should have in future that is not too difficult to implement.







By: eztup - eztup

RE: Formatting a textfield depending on conte

2005-04-13 08:15

Oh yes, that would be exactly what we need... But for now we could convince our customer to do it without colors. Let's hope there will be a feature like that in the future :)





By: David - dnarmitage

RE: Formatting a textfield depending on content?

2005-04-11 14:17

Try using the Print when expression using two copies of the field concerned, one formatted red, one black.


For the red one add a print when expression to check if the value is less than zero, and then a print when expression of 0 or greater for the black one. Set top and left of these to the same value so they completely overlap and hey presto!


Probably an expression something like this:

($F{NUMBER}).intValue() < 0





By: Jhonny Bravo - ac48

Problems Starting Up

2005-07-16 06:13

i am trying to make a new report but i keep on getting this error i m fairly new to iReports. Can any one of you help me on the same.


net.sf.jasperreports.engine.JRException:?Report?design?not?valid?:? ?????1.?Field?not?found?:?name ?????2.?Field?not?found?:?C_BPartner_ID ????at?net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.compileReport(JRAbstractJavaCompiler.java:111) ????at?net.sf.jasperreports.engine.design.JRDefaultCompiler.compileReport(JRDefaultCompiler.java:137) ????at?net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:142) ????at?net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:130) ????at?it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:336) ????at?java.lang.Thread.run(Thread.java:534)





By: Andrey - andfedotov

RE: Formatting a textfield depending on content?

2005-07-25 02:41

Take a loot at "tips and tricks" documentation of JasperReports.


You can put in the same place two text fields, one on top of the other, both displaying the same value, but having different formats: one black and the other bold and red.

In addition, you should make use of the <printWhenExpression> element that is available for every report element and switch between those two text fields.


The red text field should be displayed only when its value is greater than 0 and the black one in the rest of the cases.


Hope it'll help

Thanks teodor for this example,


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

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...