我有texfield和标签我想根据texfield的值更改标签的背景颜色,如果texfield的值不为null,那么标签的背景颜色必须改变。
<style name="Color1">
<conditionalStyle>
<conditionExpression><![CDATA[$F{check1}=="0.00"]]></conditionExpression>
<style mode="Opaque" backcolor="#4F110F"/>
</conditionalStyle>
</style>
<textField isBlankWhenNull="true">
<reportElement x="140" y="50" width="34" height="24" backcolor="#4F110F" uuid="a792c8a7-ad7e-4f28-b8c0-cc0fce54030a"/>
<textFieldExpression><![CDATA[($F{check1} != null) ? $F{check1} : "0.00"]]></textFieldExpression>
</textField>
上面是textfield的texfield条件表达式 以下是标签
<staticText>
<reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Opaque" x="180" y="57" width="40" height="18" forecolor="#120808" backcolor="#FAFAFA" uuid="1f31c82f-cfca-4930-bee9-890c0dacca8d">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box topPadding="0" leftPadding="0">
<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="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<text><![CDATA[Yes]]></text>
</staticText>
答案 0 :(得分:0)
尝试将“Color1”样式应用于您的StaticText元素,如下所示:
<staticText>
<reportElement style="Color1" positionType="Float" ... >
...
</reportElement>
...
</staticText>
答案 1 :(得分:0)
首先从标签上删除Forecolor,背景色,模式。并添加你的风格。
<staticText>
<reportElement style="Color1" positionType="Float" stretchType="RelativeToBandHeight" x="180" y="57" width="40" height="18" uuid="1f31c82f-cfca-4930-bee9-890c0dacca8d">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<box topPadding="0" leftPadding="0">
<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="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="11" isBold="true"/>
</textElement>
<text><![CDATA[Yes]]></text>
</staticText>
如果你的情况,$ F {check1} ==&#34; 0.00&#34;不管用。然后尝试java的.equals属性。 $ F {check1} .equals(&#34; 0.00&#34;)或将其转换为相同的数据类型 比如新的BigDecimal($ F {check1})== new BigDecimal(&#34; 0.00&#34;)