Example usage for com.lowagie.text Chunk setBackground

List of usage examples for com.lowagie.text Chunk setBackground

Introduction

In this page you can find the example usage for com.lowagie.text Chunk setBackground.

Prototype

public Chunk setBackground(Color color) 

Source Link

Document

Sets the color of the background Chunk.

Usage

From source file:org.unitime.timetable.webutil.PdfWebTable.java

License:Open Source License

private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color,
        Color bgColor) {/*  www. j a  v  a2 s . c om*/
    Font font = PdfFont.getFont(bold, italic, underline, color);
    Chunk chunk = new Chunk(text, font);
    if (bgColor != null)
        chunk.setBackground(bgColor);
    if (cell.getPhrase() == null) {
        cell.setPhrase(new Paragraph(chunk));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(chunk);
    }
    float width = 0;
    if (text.indexOf('\n') >= 0) {
        for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();)
            width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
    } else
        width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize()));
    return width;
}