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

setting backcolor at runtime for a text


rajesh

Recommended Posts

  • Replies 19
  • Created
  • Last Reply

Top Posters In This Topic

I think that rajesh thought of setting the background color at runtime.

I have an idea for this: take 2 fields, one for each background color, and let the two field be displayed in change by setting the "display when expression" in a way that it is true every second time.

Link to comment
Share on other sites

Hello all,

 

The "printWhenExpression" is a good solution if you have 2 or 3 colors. What if I don't know my backcolor until runtime and it could be any color of the rainbow? Any solution for this problem?

 

Many thanks,

 

Remus

 

 

EDIT: at runtime to until runtime

Post edited by: rlacatus, at: 2006/08/25 14:30

Link to comment
Share on other sites

I've used 2 textfields on the same location with the same expression, each having its corresponding backcolor.

 

Then, we have the variable in iReport called $VREPORT_COUNT} that is incremented at every record/line.

 

So for the textfield with the backcolor that i want to display at the first line and then every 2nd alternation, i put in PrintWhenExpression:

new Boolean($V{REPORT_COUNT}.intValue()%2==0)

 

and for the textfield with the backcolor that i want to display at the 2nd line and then at every 2nd alternation, i put in PrintWhenExpression:

new Boolean($V{REPORT_COUNT}.intValue()%2==1)

 

Hope this helps for you.

 

Monica

Link to comment
Share on other sites

What do you mean by conditional stylesheet :sick: . I could follow Monika. But I don't know how a conditional stylesheet works here.

 

Isn't iReport creating the whole thing?

 

Anyway Monika's way sounds good for me, I only have the problem that I don't know how to set the background color for my 2nd rectangle. At least not with iReport-1.1.0 :(

 

Is it possible at all. Or do I have to add the background color by hand in iReports' created .jrxml file?

 

I can't simply upgrade to iReports-1.2.5 because I depend on JasperReports jasperreports-1.1.1.jar JAR file and have no authority to change that :whistle: .

 

Regards,

Darya

Link to comment
Share on other sites

Giulio, you forgot that I stuck with iReport-1.1.0

 

What you say seems to work with the latest iReport-1.2.5 release and I am not sure whether I can use this latest release because I depend on jasperreports-1.1.1.jar.

 

Anyway, I should give it a try first.

 

Regards,

Darya

Link to comment
Share on other sites

I think you can use your reports with jr 1.2.5 without recompile your reports and/or your application.

 

Anyway the steps are:

 

1. Be sure the background of your element is not set (if it is, you should see the background property displayed in bold in the element properties sheet: press the special button to reset this propety (it's the button with a lottle crown.

 

2. In the styles window, create a new style and set for this style the background property (this will be the default value for the background).

 

3. Drag and drop the style over your element

 

4. Back to the style, and add a condition in the conditions list. For each condition you can set a different value for the background property.

 

Hope it's clear.

 

Giulio

Link to comment
Share on other sites

  • 2 months later...

I want to change the background colour to show results of the search - for example, highlight all elements that contain the word "foobar". Is there something I can put into the conditional expression that applies to all fields? I mean, it is not very flexible to have something like

Code:
new Boolean($F{f1}.equals("foobar"«») for every field I have in the report. Plus, I want to include static field in the search too.

 

If this is not possible, can I modify the style from Java of individual JRPrintElement contained in the JasperPrint object?

Link to comment
Share on other sites

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