2013-11-09 2 views
3

pdf 테이블 alernative 행의 색상 나는 pdf 파일의 텍스트를 사용하여 데이터베이스에서 pdf 파일을 생성하고 있습니다. 이제 필자는 필자가 필요로하는 다른 색상의 얼룩말 (회색 및 흰색) 하지만 난itext를 설정하는 방법

 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")); 
     } 

이 제발 도와주세요 .. 여기

내 코드는 ... 그렇게하는 방법을 잘 모릅니다. 미리 감사드립니다.

답변

8
boolean b = true; 
for(PdfPRow r: table.getRows()) { 
    for(PdfPCell c: r.getCells()) { 
    c.setBackgroundColor(b ? BaseColor.GREY : BaseColor.WHITE); 
    } 
    b = !b; 
} 
+0

나는 번갈아 줄을 필요로하지만, 여기에서는 번갈아 가며 열 – Adi

+0

@Adi를 고쳤습니다. –

관련 문제