klinder Posted May 11, 2009 Share Posted May 11, 2009 I have figured out how to create a scriptlet and get it in my report and running. The problem I'm having is doing something simple.Depending on a field value (txtRegCatCode) I want to change the background and foreground of a rectangle. Is this possible and if so how can I go about doing it?I've looked in the samples and see a setVariableValue method but what I need to change isn't a variable but instead a property. I see there is a setData() method but not sure what it takes and if I could use this to do what I needed.Below is my test scriptlet:Code:import net.sf.jasperreports.engine.JRDefaultScriptlet;import net.sf.jasperreports.engine.JRScriptletException;public class SecurityColor extends JRDefaultScriptlet { public String getColor() throws JRScriptletException { String category = (String) this.getFieldValue("txtRegCatCode"); String color = "BLACK"; if(category.compareToIgnoreCase("foo") == 0){ color = "BLUE"; } if(category.compareToIgnoreCase("bar") == 0){ color = "RED"; } return color; }} Link to comment Share on other sites More sharing options...
Gaby38 Posted May 11, 2009 Share Posted May 11, 2009 Hello,If I were you, I would use a conditionnal style. I already used that to have a list with alternate colors.You define a style for your report and add conditionnal styles triggered by the value of your test field having adequate background color properties. And you attach this style to your rectangle.I do it with iReport.Hope this helps Link to comment Share on other sites More sharing options...
klinder Posted May 11, 2009 Author Share Posted May 11, 2009 How do I add conditional styles? I know how to add a style but don't see how it can be added to an object with a condition. Do I do that from within the scriptlet? 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