Change text field data color (Foreground color) based on condition in JasperReports

你说的曾经没有我的故事 提交于 2019-12-17 02:49:24

问题


I'm new to JasperReports. I'm designing a report using iReport. I have three values x,y,z. If z < y then the data color for z should be changed to 'black' & if z > x then data color of z should be changed to 'red'. Please tell me how to do it.

I am using JDeveloper to develop desktop app. and iReport to design JasperReport.


回答1:


You can use Conditional styles for solving this issue.

The sample:

<style name="ZFieldStyle">
    <conditionalStyle>
        <conditionExpression><![CDATA[$F{Z} < $F{Y}]]></conditionExpression>
        <style forecolor="#000000"/>
    </conditionalStyle>
    <conditionalStyle>
        <conditionExpression><![CDATA[$F{Z}>$F{X}]]></conditionExpression>
        <style forecolor="#FF0000"/>
    </conditionalStyle>
</style>
...
<field name="X" class="java.lang.Integer"/>
<field name="Y" class="java.lang.Integer"/>
<field name="Z" class="java.lang.Integer"/>
...
<textField>
    <reportElement style="ZFieldStyle" x="200" y="0" width="100" height="20"/>
    <textElement/>
    <textFieldExpression><![CDATA[$F{Z}]]></textFieldExpression>
</textField>


来源:https://stackoverflow.com/questions/8754448/change-text-field-data-color-foreground-color-based-on-condition-in-jasperrepo

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