adry Posted August 28, 2007 Share Posted August 28, 2007 Hello ,i want to set the background color of a rectangle with a value sent as a parameter, Can anybody help ? Link to comment Share on other sites More sharing options...
niik Posted August 28, 2007 Share Posted August 28, 2007 This is a solution to change a style attribute after the call toCode:jasperPrint = JasperFillManager.fillReport(rptfile, parameters, dataSource); 1. In ireports define a style that contains a default background color. Apply this style to the rectangle(s). 2. After calling fillReport(), find the style and change its background color attribute:Code:[code]if (hexVal != null && !"".equals(hexVal)) { Color userColor = new Color(R, G, B ); JRStyle[] styleList = jasperPrint.getStyles(); for (int j = 0; j < styleList.length; j++) { System.out.println("style " + j + " is " + styleList[j].getName()); if (styleList[j].getName().equals("tableHeader"«»)) { System.out.println("found tableHeader"«»); styleList[j].setBackcolor(userColor); jasperPrint.addStyle(styleList[j], true); } }} 3. Export your report.Post edited by: niik, at: 2007/08/28 15:52 Link to comment Share on other sites More sharing options...
Teodor Danciu Posted August 28, 2007 Share Posted August 28, 2007 Hi, If it is about a parameter, then it means you know the color even before filling the report and the rectangle will have the same color no matter how many times it gets rendered in the report.If so, then you could try "alter" the rectangle's color by making modifications on the compiled report template at runtime, as shown in the /demo/samples/alterdesign sample provided with the project. But if you are actually looking for a solution to change the color of the rectangle with every record (dependent on a field or variable, not only parameter), then this is not possible. If the number of different colors is limited, then a conditional style could be used to make the rectangle color change based on runtime conditions. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
adry Posted August 30, 2007 Author Share Posted August 30, 2007 Hi, Where i can find the sample you mentioned (/demo/samples/alterdesign) ?Can you provide a link ? Link to comment Share on other sites More sharing options...
lucianc Posted August 30, 2007 Share Posted August 30, 2007 Read this topic to see where to get the JR samples from. HTH,Lucian Link to comment Share on other sites More sharing options...
newsletter6 Posted August 31, 2007 Share Posted August 31, 2007 But if you are actually looking for a solution to change the color of the rectangle with every record (dependent on a field or variable, not only parameter), then this is not possible. If the number of different colors is limited, then a conditional style could be used to make the rectangle color change based on runtime conditions.It is possible, with a trick: I generate 1x1 Pixel images and put those into my DataSource, as Colors are not supported directly. Then I create an image field in iReport and let JasperReports fill it from the image I generated from the color information. This works for me: Code:BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB«»);img.setRGB(0, 0, color.getRGB()); Regards,Mathis Link to comment Share on other sites More sharing options...
pilabrem Posted July 29, 2020 Share Posted July 29, 2020 You can do that with net.sf.jasperreports.style.* element level properties (for which you can have expressions as values).In your case you would need <rectangle> <reportElement ...> <propertyExpression name="net.sf.jasperreports.style.backcolor">$P{someColor}</propertyExpression> ... </reportElement> ...</rectangle> Link to comment Share on other sites More sharing options...
pilabrem Posted July 29, 2020 Share Posted July 29, 2020 You can do that with net.sf.jasperreports.style.* element level properties (for which you can have expressions as values).In your case you would need <rectangle> <reportElement ...> <propertyExpression name="net.sf.jasperreports.style.backcolor">$P{someColor}<propertyExpression> ... <reportElement></rectangle>[/code] 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