2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Laurent Maillard - maillard Subreports not floating 2003-05-28 00:09 I'm using 8 subreports within a main report, all written with the JasperReports API, each of them using his own datasource. The height of these subreports can vary according to the number of entry in their datasource. My problem is I can't get the subreports to float within the main report and be displayed one below another. On the contrary, they are covering each other. This is the code I use to add each subreport to the main report (I use the 0.4.5 JasperReports distribution). private synchronized void addSubreport(JasperDesign jasperDesign, JRDesignBand band, String name, int yPosition) throws JRException { JRDesignParameter parameter = new JRDesignParameter(); parameter.setName(name + "Subreport"); parameter.setValueClass(java.io.File.class); jasperDesign.addParameter(parameter); parameter = new JRDesignParameter(); parameter.setName(name + "DataSource"); parameter.setValueClass(dori.jasper.engine.JRDataSource.class); jasperDesign.addParameter(parameter); JRDesignSubreport subreport = new JRDesignSubreport(); subreport.setY(yPosition); subreport.setHeight(35); //source subreport JRDesignExpression expression = new JRDesignExpression(); expression.setValueClass(java.io.File.class); expression.setText("$P{" + name + "Subreport}"); subreport.setExpression(expression); //datasource expression = new JRDesignExpression(); expression.setValueClass(dori.jasper.engine.JRDataSource.class); expression.setText("$P{" + name + "DataSource}"); subreport.setDataSourceExpression(expression); subreport.setPositionType(JRElement.POSITION_TYPE_FLOAT); subreport.setUsingCache(true); band.addElement(subreport); } For each subreport I use a greater value for the yPosition method parameter. Although I use the setPositionType() method, this makes no difference, the subreports don't float. Am I missing something or is it a bug in JasperReports (since this code worked just well with version 0.4.2). If anyone has an idea, I would really appreciate. Thanks, Laurent By: Teodor Danciu - teodord RE: Subreports not floating 2003-05-28 00:24 Hi, Have you tried to make your subreport element at least 1 pixel wide as I already suggested you? subreport.setWidth(1); In order for them to float, they have to be at least 1 pixel wide and to be placed one below de other, so that they can push one another downwards when stretching. If you subreport have zero width or if they do not align on the verical axis, they do not float. Thank you, Teodor By: Laurent Maillard - maillard RE: Subreports not floating 2003-05-28 00:39 Sorry for the double post, that wasn't intended. My subreports now float perfectly, thanks for the help. Laurent 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