我正在使用 itext pdf 库从数据库生成 pdf 文件。现在我需要我必须显示不同颜色的 pdf 表的替代行,就像斑马色(灰色和白色) 但我不知道该怎么做...
这是我的代码..
PdfPTable table = new PdfPTable(10);
table.setTotalWidth(100);
table.setWidthPercentage(100);
while (rs.next()) {
table.addCell(rs.getString("date"));
table.addCell(rs.getString("time"));
table.addCell(rs.getString("source"));
table.addCell(rs.getString("destination"));
table.addCell(rs.getString("extension"));
}
请帮帮我。 提前致谢。
最佳答案
boolean b = true;
for(PdfPRow r: table.getRows()) {
for(PdfPCell c: r.getCells()) {
c.setBackgroundColor(b ? BaseColor.GREY : BaseColor.WHITE);
}
b = !b;
}
关于java - 如何在 java 中设置 itext pdf 表替代行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19874176/