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

Dynamically change color of textfield


dunham

Recommended Posts

Hi

I have multiple reports and want to be able to set the background color ("backcolor") of a textfield element via parameter. (Parameter: "customColor: #333333")

This parameter has a default value of "#000000" (black), when I define a custom color through my Java program which kicks of the report I want all reports to use that color as background.

I do not want to use styles because I want to be able to change the color easily (not having to go through all reports and changing the conditional style). I want to set this parameter once in all reports and then not have to change the templates again when I decite to use another color.

Can this be done? (backcolor="$P{customColor}" does not work:(

If not what would be the best approach?

<textField>

<reportElement mode="Opaque" x="2" y="16" width="580" height="18" forecolor="#333333" backcolor="#000000" uuid="e111bb79-af6d-4d24-896e-271220ef1f59"/>
<textElement verticalAlignment="Middle" markup="none">
<font fontName="SansSerif" size="14" isBold="true"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$P{TRANSLATE_SCRIPTLET}.translate("lKundenauszug")]]></textFieldExpression>
</textField>
 
[/code]
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 months later...

Thank you lucianc for your reply

I have created a test report with my element:

<textField>    <reportElement key="" x="-13" y="170" width="580" height="18" uuid="77c11b23-d15f-4a27-a4bb-c00812d9656b">     <propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$P{colorcustom}]]></propertyExpression>    </reportElement>    <textElement verticalAlignment="Middle" markup="none">     <font fontName="SansSerif" size="14" isBold="true"/>     <paragraph leftIndent="2"/>    </textElement>    <textFieldExpression><![CDATA["color: " + $P{colorcustom}]]></textFieldExpression>   </textField>[/code]

I set this parameter to "#000000" however the background is still white (should be black).

What am I doing wrong?

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