When you make dynamic report, sometimes you need to add subreport. You can add subreport and also set its position dynamically. Also you need to pass data source with this.

Here is a code snippet to understand that how can you make subreport in main report dynamically.

JRDesignBand  band = new JRDesignBand();
band.setheight(50)
JasperDesign jasperDesign = new JasperDesign();
JRDesignSubreport sub = new JRDesignSubreport(jasperDesign);
sub.setX(0); 
sub.setY(0); 
sub.setHeight(20);
sub.setWidth(355);
sub.setPositionType(PositionTypeEnum.FLOAT);

JRDesignExpression expression = new JRDesignExpression();

expression.setValueClass(net.sf.jasperreports.engine.data.
JRBeanCollectionDataSource.class);

expression.setText("new net.sf.jasperreports.engine.data.
JRBeanCollectionDataSource($F{listNameOfObject})");

/* you can send list of object. This list should save 
field of main report sub.setDataSourceExpression(expression);*/
expression = new JRDesignExpression();	

/* always make a new instance of JRDesignExpression, 
otherwise it will insert previous value */

expression.setText(""path/to/subreport""); 

// be careful while setting path of subreport. 
//Follow this syntax to set path

sub.setExpression(expression);
band.addElement(sub);
jasperDesign.setTitle(band);

Note: addition of method setY() and setHeight of subreport should not exceed band height. Otherwise it will throw an exception that “your height is exceeding band height”. This is a restriction of jasper report that in band no element should cross its height.