Beate Niendorf wrote:

Now I bounced in another little problem:
I studied the example for creating a checkbox: http://itextdocs.lowagie.com/examples/com/lowagie/examples/forms/FormCheckbo
x.java
Is there a more simple way to create a default checkbox?

<>There is a class RadioCheckField:
RadioCheckField check = new RadioCheckField(writer, rect, name, "On");
check.setCheckType(RadioCheckField.TYPE_CROSS); writer.addAnnotation(check.getCheckField());
But it only has a limited number of default appearances.

I really don't like
to draw the images for "checked" and "not checked". ;)
It's nothing to be afraid of ;-) I usually create an array with appearances
that I can reuse. For instance:

PdfAppearance[] onOff = new PdfAppearance[2];
onOff[0] = cb.createAppearance(20, 20);
onOff[0].rectangle(1, 1, 18, 18);
onOff[0].stroke();
onOff[1] = cb.createAppearance(20, 20);
onOff[1].setRGBColorFill(255, 128, 128);
onOff[1].rectangle(1, 1, 18, 18);
onOff[1].fillStroke();
onOff[1].moveTo(1, 1);
onOff[1].lineTo(19, 19);
onOff[1].moveTo(1, 19);
onOff[1].lineTo(19, 1);
onOff[1].stroke();

I reuse this array for every checkbox I need:

field.setWidget(rect, PdfAnnotation.HIGHLIGHT_INVERT);
field.setFieldName(name);
field.setValueAsName("Off");
field.setAppearanceState("Off");
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1]);
writer.addAnnotation(field);

HTH,
Bruno


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to