Question

I want to set 4 different colours in 4 border of a cell using itextpdf.When i used the below the code itz not working.Please help me to solve this.

private static  PdfPTable insertCell(PdfPTable table, String text, int align, int colspan, Font font){

        PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); 
        cell.setHorizontalAlignment(align);  
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);        
        cell.setColspan(colspan);  

        cell.setBackgroundColor(new BaseColor(hex2Rgb(color)));             
        cell.setBorderColorTop(BaseColor.BLUE);
        cell.setBorderWidthTop(1f);
        cell.setBorder(Rectangle.TOP);
        cell.setBorderColorRight(BaseColor.ORANGE);
        cell.setBorderWidthRight(1f);
    cell.setBorder(Rectangle.RIGHT);
        cell.setBorderColorBottom(BaseColor.RED);
        cell.setBorderWidthBottom(1f);
        cell.setBorder(Rectangle.BOTTOM);
        cell.setBorderColorLeft(BaseColor.GREEN);
        cell.setBorderWidthLeft(1f);
        cell.setBorder(Rectangle.LEFT);

        cell.setMinimumHeight(25f);
        //add the call to the table   
        table.addCell(cell);

        return table;
        }  
Was it helpful?

Solution

Why you set different borders to the same cell? It will remove the previous set colors. Just set the border colors only. Remove all

cell.setBorder(Rectangle.Something); 

and have a go.

If You want a particular border type then set it and set the color.But don't reset the border after you set color

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top