peter.diazdeleon Posted May 23, 2017 Share Posted May 23, 2017 <textField pattern="#0.000;(#0.000-)"> <reportElement x="430" y="2" width="30" height="20" uuid="4eba3e3c-c0d5-4da0-a71a-b805092110a9"> <property name="com.jaspersoft.studio.unit.height" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="pixel"/> </reportElement> <textElement textAlignment="Right" markup="html"> <font size="8"/> </textElement> <textFieldExpression><![CDATA[$F{previous4} < 120.0 ? "<font color=red>" + $F{previous4} + "</font>" : "<font color=black>" + $F{previous4} + "</font>"]]></textFieldExpression> </textField> I need to change a color of a field (java double) based upon is value to RED. That is working fine. What does not work is the formating of the number. When using HTML markup 37.50 becomes 37.5 When using HTML markup 37.00 becomes 37.0 Howeverm, when using HTML markup 37.55 becomes 37.55 Any ideas? Thank you Peter Link to comment Share on other sites More sharing options...
szaharia Posted May 23, 2017 Share Posted May 23, 2017 Instead of html markup, you could use a conditional style or the net.sf.jasperreports.style.forecolor property expression for that element. Link to comment Share on other sites More sharing options...
peter.diazdeleon Posted May 23, 2017 Author Share Posted May 23, 2017 Thank you.Not really sure how I make use of net.sf.jasperreports.style.forecolor property expressionNot really finding any examples on the web.Any help appreciated.Thanks Peter Link to comment Share on other sites More sharing options...
peter.diazdeleon Posted May 23, 2017 Author Share Posted May 23, 2017 Thank you. Not really sure how I make use of net.sf.jasperreports.style.forecolor property expression Not really finding any examples on the web. Any help appreciated. Thanks Peter Link to comment Share on other sites More sharing options...
szaharia Posted May 23, 2017 Share Posted May 23, 2017 Below is an example of using net.sf.jasperreports.style.forecolor property expression: <propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{previous4} < 120 ? "red" : "black"]]></propertyExpression>[/code] Link to comment Share on other sites More sharing options...
peter.diazdeleon Posted May 24, 2017 Author Share Posted May 24, 2017 Thank you for the example. Now the next quetion. I am pretty new to Jasper. Using Jasper 6.3.1 on OSX in case it matters.I cut and pasted the above code into the "Expression Field of the "Text Field" component.I changed the Markup from HTML to Styled. All I get are errors when when previewing the report.What am I missing?Thank youPeter Link to comment Share on other sites More sharing options...
szaharia Posted May 24, 2017 Share Posted May 24, 2017 There is no more need of the 'Markup' attribute. Your texfield should look like below, in the JRXML file:<textField pattern="#0.000;(#0.000-)"> <reportElement x="430" y="2" width="30" height="20" uuid="4eba3e3c-c0d5-4da0-a71a-b805092110a9"> <property name="com.jaspersoft.studio.unit.height" value="pixel"/> <property name="com.jaspersoft.studio.unit.width" value="pixel"/> <propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{previous4} < 120 ? "red" : "black"]]></propertyExpression> </reportElement> <textElement textAlignment="Right"> <font size="8"/> </textElement> <textFieldExpression><![CDATA[$F{previous4}]]></textFieldExpression></textField>[/code] Link to comment Share on other sites More sharing options...
peter.diazdeleon Posted May 24, 2017 Author Share Posted May 24, 2017 Okay I am not understanding and I am not being clear all at the same time.Am I editing the JRXML file directly and updating it with the above code or am I doing this through the Jaspersoft 6.3.1 Community Edition?If I am editing the file directly how is it that I don't lose my changes?Thank youPeter Link to comment Share on other sites More sharing options...
peter.diazdeleon Posted May 24, 2017 Author Share Posted May 24, 2017 Figured it out. Finally found where in Jasper Studio you add the aditional properties. Thanks for the help is getting in the right direction!Peter Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now