我正在使用Dynamicreports创建报告。有我的代码。当我运行它给错误。我的内容如此之大(细节)。请帮我解决这个问题。当我的内容(细节)是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();
}
答案 0 :(得分:1)
这是dynamicReport中一个非常常见的问题,无论何时使用任何详细信息,页眉或页脚,其高度或宽度都超过页面尺寸。
尝试一件事,将您的详细信息组件划分为horizontalList组件块(将它们分成最大部分)。我这样做并在逻辑上处理它们。您应该更喜欢添加
report.detail(cmp1);
然后
report.detail(cmp2);
当你不确定高度时,将这两个组件添加到一个包含cmp1和cmp2的组件'cmp'中。