Jump to content
We've recently updated our Privacy Statement, available here ×

Conditional Styles / Formatting


mdemetri2

Recommended Posts

I have been trying to figure out how to apply the Style Formatting to a field e.g. if it = 1 then background colour is green, 2 = organge etc.

I have tried various exmaple that I did find and they dont work. Can someone post what should be the correct way?

Many thanks

Demetri

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

in you have a finite set of option to create different styles try this:

create a new stile:

-set a name (ex: AlternativeStyle)
-set the style option for the default look...
-then add a new rule:   new Boolean ($F{IT}.matches("1"))  (or an integer expressione if you use integer...)
-click on this rule and then set the new look...
-create a new rule:       new Boolean ($F{IT}.matches("2"))  (or an integer expressione if you use integer...)
- click on this rule and set another look...
...

then apply this style ho a cell...

in the jasper xml there is something like this:

 


 

<style
        name="AlternativeStyle"
        isDefault="false"
    >

        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean ($F{IT}.matches("2"))]]></conditionExpression>
            <style
                name="AlternativeStyle"
                isDefault="false"
                backcolor="#33FF33"
            />
        </conditionalStyle>
            <conditionalStyle>
                <conditionExpression><![CDATA[new Boolean ($F{IT}.matches("2"))]]></conditionExpression>
                <style
                    name="AlternativeStyle"
                    isDefault="false"
                    backcolor="#FF0000"
                />
            </conditionalStyle>
                <conditionalStyle>
                    <conditionExpression><![CDATA[new Boolean ($F{IT}.matches("3"))]]></conditionExpression>
                    <style
                        name="AlternativeStyle"
                        isDefault="false"
                        backcolor="#0000CC"
                    />
                </conditionalStyle>
    </style>

 

and the textfiled you applied the style to:

<textField .....>
                    <reportElement
                        style="AlternativeStyle"
                        ..../>


 ______________________________

( if it works... KARMA points please! :)  )

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...