Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中使用itextpdf设置表格单元格边框的不同颜色_Java_Itextpdf - Fatal编程技术网

如何在java中使用itextpdf设置表格单元格边框的不同颜色

如何在java中使用itextpdf设置表格单元格边框的不同颜色,java,itextpdf,Java,Itextpdf,我想用itextpdf在一个单元格的4个边框中设置4种不同的颜色。当我使用下面的代码时,itz不起作用。请帮我解决这个问题 private static PdfPTable insertCell(PdfPTable table, String text, int align, int colspan, Font font){ PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); cell.s

我想用itextpdf在一个单元格的4个边框中设置4种不同的颜色。当我使用下面的代码时,itz不起作用。请帮我解决这个问题

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

为什么要为同一单元格设置不同的边框?它将删除以前设置的颜色。只需设置边框颜色即可。全部删除

cell.setBorder(Rectangle.Something); 
试一试


如果您需要特定的边框类型,请进行设置并设置颜色。但在设置颜色后不要重置边框

也可以通过单击左侧右侧符号接受答案:D