gpt4 book ai didi

java - iText,在 PdfPTable 列中插入新的空行

转载 作者:行者123 更新时间:2023-11-30 08:03:05 26 4
gpt4 key购买 nike

如何在 PdfPTable 列中插入新的空行。 \nn 个空格 并没有为我解决问题。这是我正在使用的java代码。

chtbc_report1_table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"H.B.G", "Some Value", "lbs/kg", "Adult M : 120lbs \n Adult F : 90lbs"},
.....
.....
//Other rows
},
new String [] {
"Investigation", "Result", "Unit", "Weight"
}
));

我想在“成人 M:120 磅 **\n** 成人 F:90 磅”之间添加一个新行

更新

这是我用于创建 PdfPTable

的代码
document.open();

PdfPTable pdfTable = new PdfPTable(chtbc_report1_table.getColumnCount());
for (int rows = 0; rows < chtbc_report1_table.getRowCount(); rows++) {
for (int cols = 0; cols < chtbc_report1_table.getColumnCount(); cols++) {
pdfTable.addCell(chtbc_report1_table.getModel().getValueAt(rows, cols).toString());

}
}
float[] columnWidths_pdfTable = new float[]{30f, 25f, 40f, 50f};
pdfTable.setWidths(columnWidths_pdfTable);
document.add(pdfTable);

document.close()

任何建议都会有所帮助。

最佳答案

哦,这确实很简单。尝试以下方法,对我来说同样有效:-

表格内容

jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"Lorem Ipsum", "Next Line here \n, Another new line\n, Two new lines\n\nI will end here"},
{"Lorem Ipsum", "Another cell to demonstrate \n\n\n\n4 New lines above and two below \n\n"}
},
new String [] {
"Text", "Long Text"
}
));

如果有效,请告诉我。并且 PdfPtable 应该是相同的。

关于java - iText,在 PdfPTable 列中插入新的空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31591806/

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