2016-05-11 10 views
0

Ich habe texfield und eine Beschriftung Ich möchte die Hintergrundfarbe der Beschriftung basierend auf dem Wert von texfield ändern, wenn der Wert von texfield nicht null ist, dann die Hintergrundfarbe der Beschriftung muss sich ändern .Wie man die Farbe des Etiketts basierend auf dem Textfeld in Jaspis ändert

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

oben ist mein texfield bedingter Ausdruck für Textfeld und unten ist das Label

<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

Mögliche Duplikate von [Ändern Textfeld Datenfarbe (Vordergrundfarbe) basierend auf der Bedingung in JasperReports] (http://stackoverflow.com/questions/8754448/change-text-field-data-color-foreground-color-based-on-condition-in-jasperrepo) –

Antwort

0

Versuchen Sie, die "Color1" Stil zu Ihrem StaticText- Element so etwas wie diese Anwendung:

<staticText> 
    <reportElement style="Color1" positionType="Float" ... > 
     ... 
    </reportElement> 
    ... 
</staticText> 
0

Entfernen Sie zuerst Forecolor, Backcolor, Modus von Ihrem Etikett. und füge deinen Stil hinzu.

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

Wenn Ihre Bedingung, $ F {check1} == "0.00" nicht funktioniert. dann versuchen Sie. EQUALS Eigenschaft von Java. $ F {check1} .equals ("0.00") oder in den gleichen Datentyp umwandeln wie neu BigDecimal ($ F {check1}) == new BigDecimal ("0.00")

Verwandte Themen