gpt4 book ai didi

java - 动态报告详细信息部分存在页面高度错误

转载 作者:太空宇宙 更新时间:2023-11-04 07:19:28 25 4
gpt4 key购买 nike

我正在使用 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();
}

最佳答案

这是动态报表中非常常见的问题,每当您详细使用任何组件时,页眉或页脚的高度或宽度超过页面尺寸。

尝试一件事,将详细组件划分为水平列表组件 block (将它们划分为最大部分)。我这样做并逻辑地处理它们。您应该更愿意添加

report.detail(cmp1);

然后

report.detail(cmp2); 

当您不确定高度时,不要将这 2 个组件添加到一个包含 cmp1 和 cmp2 的组件“cmp”中。

关于java - 动态报告详细信息部分存在页面高度错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19517994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com