How to make the backcolor in a style a parameter using jasper reports?

15 Views Asked by At

I made a table using jasper report and I want to make the backcolor of the table header a parameter so I can customize it for each report how I want to using java code

enter image description here

below is the jrxml code for the style

<style name="Table 1_CH" mode="Opaque" backcolor="#C1C4C7">
        <box>
            <pen lineWidth="0.5" lineColor="#B7BBBD"/>
            <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#B7BBBD"/>
            <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
            <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#B7BBBD"/>
            <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
        </box>
    </style>

this is how it is used for a table column

 <jr:column width="80" uuid="17804f70-2181-4f65-ad1e-05934f747fd3">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:columnHeader style="Table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="80" height="30" uuid="dbd7884c-e356-4e2f-999c-e477213c8e45"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font isBold="true" pdfFontName="Helvetica-bold"/>
                                </textElement>
                                <text><![CDATA[CODE]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table 1_TD" height="30">
                            <textField>
                                <reportElement x="0" y="0" width="80" height="30" forecolor="#000505" uuid="cb7f9181-4d89-49c5-9d19-1bbbda926e78">
                                    <property name="com.jaspersoft.studio.unit.x" value="px"/>
                                </reportElement>
                                <box>
                                    <pen lineColor="#BDBDBD"/>
                                    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                </box>
                                <textElement textAlignment="Justified" verticalAlignment="Middle"/>
                                <textFieldExpression><![CDATA[$F{shortName}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>

I want the backcolor #C1C4C7 to be a parameter, when I tried to simply assign the parameter to the backcolor it didn't work and when I used <propertyExpression name="net.sf.jasperreports.style.backcolor">$P{someColor}</propertyExpression> it didn't allow me either , any thoughts about that ?

0

There are 0 best solutions below