我正在使用动态报告创建报告。有我的代码。当我运行它给出错误。我的内容这么大(详细)。请帮我解决这个问题。当我的内容(详细信息)为 10 行时,此代码运行良好。但是当我的内容(详细信息)很大时,它会出错。
错误:
net.sf.dynamicreports.report.exception.DRException: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. The detail section, the page and column headers and footers and the margins do not fit the page height.
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperReport(JasperReportBuilder.java:279)
at net.sf.dynamicreports.jasper.builder.JasperReportBuilder.toJasperPrint(JasperReportBuilder.java:309)
at dynamicjusper.NewJFrame.jButton5ActionPerformed(NewJFrame.java:606)
at dynamicjusper.NewJFrame.access$400(NewJFrame.java:78)
at dynamicjusper.NewJFrame$5.actionPerformed(NewJFrame.java:164)
+等..
代码 :
StyleBuilder boldStyle = stl.style().bold();
StyleBuilder boldCenteredStyle = stl.style(boldStyle).setHorizontalAlignment(HorizontalAlignment.CENTER);
StyleBuilder columnTitleStyle = stl.style(boldCenteredStyle).setBorder(stl.pen1Point()).setBackgroundColor(Color.LIGHT_GRAY);
FontBuilder boldFont = stl.fontArialBold().setFontSize(12);
StyleBuilder titleStyle = stl.style(boldCenteredStyle).setVerticalAlignment(VerticalAlignment.MIDDLE).setFontSize(15);
StyleBuilder DetailHeaderStyle = stl.style(boldStyle).setForegroundColor(Color.BLUE);
try {
JasperReportBuilder report = report();
report.setDefaultFont(stl.fontCourierNew().setFontSize(8));
//page header
report.pageHeader(cmp.horizontalList()
.add(
cmp.image("./image.gif").setFixedDimension(80, 80).setHorizontalAlignment(HorizontalAlignment.LEFT),
cmp.text("TEST").setStyle(titleStyle).setHorizontalAlignment(HorizontalAlignment.LEFT),
cmp.text("Sub Text").setStyle(titleStyle).setHorizontalAlignment(HorizontalAlignment.RIGHT))
.newRow()
.add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(10)));
String Content = jTextArea1.getText();
String[] PAGECONTENT = Content.split("");
for (int i = 0; i < PAGECONTENT.length; i++) {
String string = PAGECONTENT[i];
String Line1;
String[] dataandheader= string.split("-----------------------------------------------------------------------------------------------------------------------------------");
for (int j = 0; j < dataandheader.length; j++) {
String string1 = dataandheader[j];
if(j<1){
try {
Scanner sc = new Scanner(string1);
while (sc.hasNextLine()) {
Line1 = sc.nextLine();
//Page Detail
report.detail(cmp.horizontalList()
.newRow()
.add(cmp.text(Line1).setStyle(DetailHeaderStyle))
);
}
} catch (Exception e) {
e.printStackTrace();
}
}else{
if(j>0 && j<dataandheader.length){
//Page Detail
report.detail(cmp.horizontalList()
.newRow()
// .add(cmp.text(text))
.add(cmp.filler().setStyle(stl.style().setTopBorder(stl.pen2Point())).setFixedHeight(5))
);
}
try {
Scanner sc = new Scanner(string1);
while (sc.hasNextLine()) {
Line1 = sc.nextLine();
//Page Detail
report.detail(cmp.horizontalList()
.newRow()
.add(cmp.text(Line1))
);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//page footer
report.pageFooter(cmp.pageXofY());//shows number of page at page footer
report.setDataSource(new JREmptyDataSource());//set datasource
JRViewer jrviwer = new JRViewer(report.toJasperPrint());
((JPanel)jrviwer.getComponent(0)).remove(0); // remove save button
((JPanel)jrviwer.getComponent(0)).remove(1); // remove refresh button
JFrame jf = new JFrame();
jf.setTitle("Test viwer");
jf.getContentPane().add(jrviwer);
jf.validate();
jf.setVisible(true);
jf.setSize(new Dimension(800,600));
jf.setLocation(300,100);
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
} catch (Exception e) {
e.printStackTrace();
}