I need help creating a checkbox. I do not want a field, but a rectangle with
an X is checked, nothing if not checked. What I have below works.
Unfortunately, when the PDF is rendered the checkboxes are slightly below
adjoining text. I wrote a method that returns a cell, which has the checkbox
in it. The calling program adds that cell to a table. I want the cell which
is added to the final table in the calling program, to be slightly higher,
so it is aligned with text in adjacent cells. Thanks

Cell column2 = p.checkBox(false);
Cell column3 = p.checkBox(false);
Cell column4 = p.checkBox(false);
Cell column5 = p.checkBox(false);
table = p.table(6,new int[] {7,7,7,7,7,65});
it = posting.iterator();
while (it.hasNext()) {
    post = (Post) it.next();
    isContact = false;
    if (post.getTranCode().equals("N01")) {
        isContact = true;
        column2 = p.checkBox(true);
    }
    if (post.getTranCode().equals("N02")) {
        isContact = true;
        column3 = p.checkBox(true);
    }
    if (post.getTranCode().equals("N03")) {
        isContact = true;
        column4 = p.checkBox(true);
    }
    if (post.getTranCode().equals("N04")) {
        isContact = true;
        column5 = p.checkBox(true);
    }
    if (isContact) {

table.addCell(p.cellDefault(ToolsMisc.shortDate(post.getEffectiveDate()),Cell.ALIGN_LEFT,0));
        table.addCell(column2);
        table.addCell(column3);
        table.addCell(column4);
        table.addCell(column5);
        table.addCell(p.cellDefault(post.getComment(),Cell.ALIGN_LEFT,0));
    }
}
doc.add(table);


    public Cell checkBox(boolean isChecked) throws Exception {
        Chunk ch = new Chunk(isChecked?"X":" ");
        Cell c = new Cell();
        c.setBorder(15);     //top, bottom, left, right
        c.setBorderWidth(1);
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setVerticalAlignment(Element.ALIGN_TOP);
        c.setUseBorderPadding(false);
        c.setUseAscender(true);
        c.add(ch);
        Table t = new Table(1);
        t.setSpaceInsideCell(0);
        t.setSpaceBetweenCells(0);
        t.setSpacing(0);
        t.addCell(c);
        t.setWidth(22);
        c = new Cell();
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setVerticalAlignment(Element.ALIGN_TOP);
        c.setUseBorderPadding(false);
        c.setUseAscender(true);
        c.add(t);
        return c;
   }



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to