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

Setting textElement background color by style tag


wildgriffon

Recommended Posts

Hi,

 

I need to set dynamically the background color property of a textElement form a Java application by <style></style> tag.

 

Setting the backcolor property the result is that only the text in the textElement has the chosen background color, but the entire textElement has the background color set as white.

 

string = "<style backcolor="yellow" pdfFontName="Helvetica-Oblique">" + string + "</style>";

 

I would like to get the same result obtained by setting the textElement background color by the object property from the iReport application, so get the entire textElement filled with the chosen background color.

 

If it isn't possible, there is an alternative like dynamically setting the background color by iReport application? For example from the "Textfield expression" property...

 

View the attached file for an example.

 

Thanks size=230]http://www.jasperforge.org/components/com_joomlaboard/uploaded/images/sample.GIF

 

Post edited by: wildgriffon, at: 2006/11/02 08:16

Post edited by: wildgriffon, at: 2006/11/02 08:29

Link to comment
Share on other sites

  • Replies 14
  • Created
  • Last Reply

Top Posters In This Topic

Why don't you place a rectangle behind your textelement with the size of the cell and make it's backgroundcolor depending at the field value. (could work with a Conditional Style).

 

Or just make the Textelemet as big as the cell (so not just 10 pixel that would be enough for display the text but for example 25 pixel that is the height of the whole row.) For stretching values you could check the "RelativeToBandHeight" attribute also.

 

so many ways are leading to Rome! ;)

 

regards

C-Box

Link to comment
Share on other sites

Hi CBox,

 

I understand what you mean, but I need to change the textElement's background with 6 or 7 different colours, and I don't have ties between the colours and the textElement value.

 

To obtain the grid in the figure I have put textElements one close to the other, can you understand? And for each one I have put the padding to zero.

 

Setting the color of the shape or change the path of possible image put behind the textElement are the same things for me, and I need to do it from my Java program (there I have my rules to set the right color).

 

Thank you

Link to comment
Share on other sites

wildgriffon wrote:

I'm wondering if I can get a solution putting a colored image behind the textElement :woohoo: , but I would like don't do it... :sick: You understand that this isn't a professional solution.

Can someone help me?
I hope :)

 

 

I tried it.

It works fine.

 

Bye

Link to comment
Share on other sites

I still don't understand why some rectangles with conditional-style for the colors doesn't work for you. If you say that the color is not tied to the fieldvalue, then why don't you pass some parameters that contain your colors that you can use within the conditional styles!??!?!

 

just don't understand why you want to use some complex images changes after the jasperprint creation. (this is, what I understood from your postings)

 

regards

C-Box

Link to comment
Share on other sites

Hy,

I have the same problem, to set the backcolor to the entire detail/detail cell(inside cell is a text element),using crosstab element .The problem is that the color codes to be used as backcolor are comming from a database and are changind often and so the conditional styles can't de used.

I tried with sytle tag but is not working :(

 

Do you have any idea ,to be implemented when the number of colors is big (there could be 20 colors or more to be used for each crosstab cell)?

 

Regards,

Cristina

Link to comment
Share on other sites

CBox wrote:

I still don't understand why some rectangles with conditional-style for the colors doesn't work for you. If you say that the color is not tied to the fieldvalue, then why don't you pass some parameters that contain your colors that you can use within the conditional styles!??!?!

just don't understand why you want to use some complex images changes after the jasperprint creation. (this is, what I understood from your postings)

regards
C-Box

 

I'm trying to use iReport software from few days, so I don't have a complete software knowledge.

 

Please, can you make me an example of what you mean?

 

Thanks.

 

Bye

Link to comment
Share on other sites

Hy,

I use a crosstab element in mai report,and in one of the cell(is the detail/detail cell) I want to put a background color that is dependent of one field value.

For example I have $F{displayColor} field and I want to do something like this

<style backcolor="$F{displayColor} ">Some text </style>

but in this case the display color covers only the "Some text" area and I want it to cover the entire tectElement that contains the value "Some text"

I can't use images because I would have to many images...I don't know exactly what colors would be displayed as these are dependent of field value

 

Regards,

Cristina

Link to comment
Share on other sites

cristinab wrote:

Hy,
I use a crosstab element in mai report,and in one of the cell(is the detail/detail cell) I want to put a background color that is dependent of one field value.
For example I have $F{displayColor} field and I want to do something like this
<style backcolor="$F{displayColor} ">Some text </style>
but in this case the display color covers only the "Some text" area and I want it to cover the entire tectElement that contains the value "Some text"
I can't use images because I would have to many images...I don't know exactly what colors would be displayed as these are dependent of field value

Regards,
Cristina

 

It's the same problem that I have found.

The problem is the generated xml code: for its structure the background color can be only applied to the text.

 

I think that a possible solution is the one that I chose: put coloured images behind the textElement and change the background color changing the path of the images.

 

I would like to understand what CBox mean, I'll wait his example.

 

Regards

Link to comment
Share on other sites

Hi again,

 

sorry for late answer, I'm quite busy at the moment :(

 

So here my sample (works without any datasource)

 

Just save and open via iReport and run without datasource!

 

Enter the value for the parameter "ColorPara1" that I created for prompting.

 

I created a style that has for two colors a different background color (red and blue)

 

So for easy check enter just the string "red" to see the rectangle that is behind my textfield in red color.

 

enter "blue" to see the same rectangle in blue color.

 

The textfield contains just dummy default value text to stretch itself, you can modify this value also to see how the rectangle stretches itself also (relative to band height) depending on content.

 

So this it how I could imagine that it could solve your problem with the different colors in a cell behind a textelement.

 

Of course you could also add the style to your textelement and make this just as high as the whole cell is. So in this case you won't need the rectangle behind!

 

Unfortunately you can't pass the color itself as parameter and use it for an element, so that's why you must create for each used color a value for the parameter you can check within the condition of the style.

 

hope I could help and I don't missunderstood your problem totally! :-)

 

hth

C-Box [file name=CBoxSmallTestReportForTrialAndError.jrxml size=7596]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/CBoxSmallTestReportForTrialAndError.jrxml[/file]

Link to comment
Share on other sites

This sort of works for me, but what happens is if a cell is null, it does not highlight.

Basically my report looks like this

 

date part1 part2 part3

11/16/06 1 1 3

11/17/06 2 1 2

11/18/06 1

 

I am passing in a boolean of true if the date is a weekend and if so fill the background color to yellow (I want to highlight the row), so the 11/18 date would be highlighted. It will only fill in the cell of part2 because it has data, part1 and part3 stay white. Is there a way to solve this?

 

Also, I tried to put a rectangle into the date header (so that 11/18/06 would be highlighted) but it overlaps the actual date, I can't send element to back. Any ideas?

Link to comment
Share on other sites

  • 7 years later...
  • 4 years 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...