Set background color in textfield from condition using iReport

寵の児 提交于 2019-12-20 03:33:05

问题


I have a problem with conditionalStyle in iReport. I have the following textFields (${nameField} = field value):

${field1}=30      ${field2}=40      ${field3}=50
${field4}=23      ${field5}=1       ${field6}=45
${field7}=34       ${field8}=20     ${field9}=0

I need set difference background in every textField depend of the value of the field. I create a new Style and set the conditions:

<style name="ColoredField">
   <conditionalStyle>
     <conditionExpression><![CDATA[$F{field1} == 300]]></conditionExpression>
    <style mode="Opaque" backcolor="#FCFF00"/>
    </conditionalStyle>
</style>

As you can see, the Style use only $F{field1}, and I need make a dynamic style (or something), that apply to every textField.


回答1:


Your question is not clear, can you be more explicit ?

  1. From my understanding , each value will mean a specific background for a textfield, in that case your conditional style value should depend on variable. Maybe using Variables in your style can suit your need.

  2. Add multiple conditional style under each style as below:

each textField can now have different background :

<style name="ColoredField">
   <conditionalStyle>
     <conditionExpression><![CDATA[$F{field1} == 100]]></conditionExpression>
    <style mode="Opaque" backcolor="#FCFFFF"/>
    </conditionalStyle>
    <conditionalStyle>
     <conditionExpression><![CDATA[$F{fiCeld1} == 200]]></conditionExpression>
    <style mode="Opaque" backcolor="#00FF00"/>
    </conditionalStyle>
    <conditionalStyle>
     <conditionExpression><![CDATA[$F{field1} == 300]]></conditionExpression>
    <style mode="Opaque" backcolor="#FCFF00"/>
    </conditionalStyle>
</style>



回答2:


I could not find a direct way to accomplish this task - you have to create a separate style for each field.

Considering this you can concentrate your effort on creating a small script that replicate the XML with the same stile for the fields you have. Then you can just copy/paste the XML into the report source file. Each time you need to change the style you will have to go back to your XML generator.




回答3:


Try ths one :

<style name="myStyle" fontName="Arial">
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{SANCTION_AMOUNT_MEASURE}.intValue() == 100)]]></conditionExpression>
        <style forecolor="#FF0000" isBold="true"/>
    </conditionalStyle>
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{SANCTION_AMOUNT_MEASURE}.intValue() == 200)]]></conditionExpression>
        <style forecolor="#00FF00" isBold="true"/>
    </conditionalStyle>
    <conditionalStyle>
        <conditionExpression><![CDATA[new Boolean($V{SANCTION_AMOUNT_MEASURE}.intValue() == 300)]]></conditionExpression>
        <style forecolor="#0000FF" isBold="true"/>
    </conditionalStyle>
</style>


来源:https://stackoverflow.com/questions/21359707/set-background-color-in-textfield-from-condition-using-ireport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!