There are 4 types of checkbox.
First is a checkbox glyph.
Second is a content control checkbox.
Using xml Syntax Highlighting
<w:sdt>
<w:sdtPr>
<w:id w:val="1092049435"/>
<w14:checkbox>
<w14:checked w14:val="0"/>
<w14:checkedState w14:font="MS Gothic" w14:val="2612"/>
<w14:uncheckedState w14:font="MS Gothic" w14:val="2610"/>
</w14:checkbox>
</w:sdtPr>
<w:sdtContent>
<w:p w:rsidR="00000000" w:rsidRDefault="00FD2C55">
<w:r>
<w:rPr>
<w:rFonts w:ascii="MS Gothic" w:eastAsia="MS Gothic" w:hAnsi="MS Gothic" w:hint="eastAsia"/>
</w:rPr>
<w:t>☐
</w:t>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>
Parsed in 0.002 seconds, using
GeSHi 1.0.8.4
The above are generally to be preferred. The other two are legacy approaches... below I've created them in Word then used the Docx4j Helper Word AddIn to generate code (you could use the webapp instead).
The first legacy approach is FORMCHECKBOX (the type you look like you want), for example:
Using xml Syntax Highlighting
<w:p w:rsidR="00000000" w:rsidRDefault="00304D34">
<w:r>
<w:fldChar w:fldCharType="begin">
<w:ffData>
<w:name w:val="Check1"/>
<w:enabled/>
<w:calcOnExit w:val="false"/>
<w:checkBox>
<w:sizeAuto/>
<w:default w:val="false"/>
</w:checkBox>
</w:ffData>
</w:fldChar>
</w:r>
<w:bookmarkStart w:id="0" w:name="Check1"/>
<w:r>
<w:instrText xml:space="preserve"> FORMCHECKBOX
</w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
<w:bookmarkEnd w:id="0"/>
</w:p>
Parsed in 0.002 seconds, using
GeSHi 1.0.8.4
Note the bookmark. You could leave that out, I think.
Using java Syntax Highlighting
import org.docx4j.wml.CTColumns;
import org.docx4j.wml.CTFFCheckBox;
import org.docx4j.wml.CTFFData;
import org.docx4j.wml.CTFFName;
import org.docx4j.wml.FldChar;
import org.docx4j.wml.CTBookmark;
import org.docx4j.wml.CTMarkupRange;
// Assume P p
// Create object for r
R r
= wmlObjectFactory.
createR();
p.
getContent().
add( r
);
// Create object for fldChar (wrapped in JAXBElement)
FldChar fldchar
= wmlObjectFactory.
createFldChar();
JAXBElement
<org.
docx4j.
wml.
FldChar> fldcharWrapped
= wmlObjectFactory.
createRFldChar(fldchar
);
r.
getContent().
add( fldcharWrapped
);
fldchar.
setFldCharType(org.
docx4j.
wml.
STFldCharType.
BEGIN);
// Create object for ffData
CTFFData ffdata
= wmlObjectFactory.
createCTFFData();
fldchar.
setFfData(ffdata
);
// Create object for name (wrapped in JAXBElement)
CTFFName ffname
= wmlObjectFactory.
createCTFFName();
JAXBElement
<org.
docx4j.
wml.
CTFFName> ffnameWrapped
= wmlObjectFactory.
createCTFFDataName(ffname
);
ffdata.
getNameOrEnabledOrCalcOnExit().
add( ffnameWrapped
);
ffname.
setVal( "Check1");
// Create object for enabled (wrapped in JAXBElement)
BooleanDefaultTrue booleandefaulttrue
= wmlObjectFactory.
createBooleanDefaultTrue();
JAXBElement
<org.
docx4j.
wml.
BooleanDefaultTrue> booleandefaulttrueWrapped
= wmlObjectFactory.
createCTFFDataEnabled(booleandefaulttrue
);
ffdata.
getNameOrEnabledOrCalcOnExit().
add( booleandefaulttrueWrapped
);
// Create object for calcOnExit (wrapped in JAXBElement)
BooleanDefaultTrue booleandefaulttrue2
= wmlObjectFactory.
createBooleanDefaultTrue();
JAXBElement
<org.
docx4j.
wml.
BooleanDefaultTrue> booleandefaulttrueWrapped2
= wmlObjectFactory.
createCTFFDataCalcOnExit(booleandefaulttrue2
);
ffdata.
getNameOrEnabledOrCalcOnExit().
add( booleandefaulttrueWrapped2
);
// Create object for checkBox (wrapped in JAXBElement)
CTFFCheckBox ffcheckbox
= wmlObjectFactory.
createCTFFCheckBox();
JAXBElement
<org.
docx4j.
wml.
CTFFCheckBox> ffcheckboxWrapped
= wmlObjectFactory.
createCTFFDataCheckBox(ffcheckbox
);
ffdata.
getNameOrEnabledOrCalcOnExit().
add( ffcheckboxWrapped
);
// Create object for sizeAuto
BooleanDefaultTrue booleandefaulttrue3
= wmlObjectFactory.
createBooleanDefaultTrue();
ffcheckbox.
setSizeAuto(booleandefaulttrue3
);
// Create object for default
BooleanDefaultTrue booleandefaulttrue4
= wmlObjectFactory.
createBooleanDefaultTrue();
ffcheckbox.
setDefault(booleandefaulttrue4
);
// Create object for bookmarkStart (wrapped in JAXBElement)
CTBookmark bookmark
= wmlObjectFactory.
createCTBookmark();
JAXBElement
<org.
docx4j.
wml.
CTBookmark> bookmarkWrapped
= wmlObjectFactory.
createPBookmarkStart(bookmark
);
p.
getContent().
add( bookmarkWrapped
);
bookmark.
setName( "Check1");
bookmark.
setId( BigInteger.
valueOf( 0
) );
// Create object for r
R r2
= wmlObjectFactory.
createR();
p.
getContent().
add( r2
);
// Create object for instrText (wrapped in JAXBElement)
Text text
= wmlObjectFactory.
createText();
JAXBElement
<org.
docx4j.
wml.
Text> textWrapped
= wmlObjectFactory.
createRInstrText(text
);
r2.
getContent().
add( textWrapped
);
text.
setValue( " FORMCHECKBOX ");
text.
setSpace( "preserve");
// Create object for r
R r3
= wmlObjectFactory.
createR();
p.
getContent().
add( r3
);
// Create object for fldChar (wrapped in JAXBElement)
FldChar fldchar2
= wmlObjectFactory.
createFldChar();
JAXBElement
<org.
docx4j.
wml.
FldChar> fldcharWrapped2
= wmlObjectFactory.
createRFldChar(fldchar2
);
r3.
getContent().
add( fldcharWrapped2
);
fldchar2.
setFldCharType(org.
docx4j.
wml.
STFldCharType.
END);
// Create object for bookmarkEnd (wrapped in JAXBElement)
CTMarkupRange markuprange
= wmlObjectFactory.
createCTMarkupRange();
JAXBElement
<org.
docx4j.
wml.
CTMarkupRange> markuprangeWrapped
= wmlObjectFactory.
createPBookmarkEnd(markuprange
);
p.
getContent().
add( markuprangeWrapped
);
markuprange.
setId( BigInteger.
valueOf( 0
) );
Parsed in 0.024 seconds, using
GeSHi 1.0.8.4
The second is an ActiveX checkbox
Using xml Syntax Highlighting
<w:r>
<w:object w:dxaOrig="1440" w:dyaOrig="1440">
<v:shapetype xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" coordsize="21600,21600" filled="f" id="_x0000_t75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f" o:preferrelative="t" o:spt="75.0">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f"/>
<o:lock aspectratio="t" v:ext="edit"/>
</v:shapetype>
<v:shape xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" id="_x0000_i1025" style="width:108.3pt;height:20.75pt" type="#_x0000_t75" o:ole="">
<v:imagedata xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId4" o:title=""/>
</v:shape>
<w:control xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId5" w:name="CheckBox1" w:shapeid="_x0000_i1025"/>
</w:object>
</w:r>
Parsed in 0.003 seconds, using
GeSHi 1.0.8.4
Using java Syntax Highlighting
// Assume P p
// Create object for r
R r
= wmlObjectFactory.
createR();
// Create object for object (wrapped in JAXBElement)
CTObject object
= wmlObjectFactory.
createCTObject();
JAXBElement
<org.
docx4j.
wml.
CTObject> objectWrapped
= wmlObjectFactory.
createRObject(object
);
r.
getContent().
add( objectWrapped
);
// Create object for control
CTControl control
= wmlObjectFactory.
createCTControl();
object.
setControl(control
);
control.
setName( "CheckBox1");
control.
setShapeid( "_x0000_i1025");
control.
setId( "rId5");
object.
setDxaOrig( BigInteger.
valueOf( 1440
) );
object.
setDyaOrig( BigInteger.
valueOf( 1440
) );
org.
docx4j.
vml.
ObjectFactory vmlObjectFactory
= new org.
docx4j.
vml.
ObjectFactory();
// Create object for shapetype (wrapped in JAXBElement)
CTShapetype shapetype
= vmlObjectFactory.
createCTShapetype();
JAXBElement
<org.
docx4j.
vml.
CTShapetype> shapetypeWrapped
= vmlObjectFactory.
createShapetype(shapetype
);
object.
getAnyAndAny().
add( shapetypeWrapped
);
// Create object for stroke (wrapped in JAXBElement)
CTStroke stroke
= vmlObjectFactory.
createCTStroke();
JAXBElement
<org.
docx4j.
vml.
CTStroke> strokeWrapped
= vmlObjectFactory.
createStroke(stroke
);
shapetype.
getEGShapeElements().
add( strokeWrapped
);
stroke.
setJoinstyle(org.
docx4j.
vml.
STStrokeJoinStyle.
MITER);
// Create object for formulas (wrapped in JAXBElement)
CTFormulas formulas
= vmlObjectFactory.
createCTFormulas();
JAXBElement
<org.
docx4j.
vml.
CTFormulas> formulasWrapped
= vmlObjectFactory.
createFormulas(formulas
);
shapetype.
getEGShapeElements().
add( formulasWrapped
);
// Create object for f
CTF f
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f
);
f.
setEqn( "if lineDrawn pixelLineWidth 0");
// Create object for f
CTF f2
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f2
);
f2.
setEqn( "sum @0 1 0");
// Create object for f
CTF f3
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f3
);
f3.
setEqn( "sum 0 0 @1");
// Create object for f
CTF f4
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f4
);
f4.
setEqn( "prod @2 1 2");
// Create object for f
CTF f5
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f5
);
f5.
setEqn( "prod @3 21600 pixelWidth");
// Create object for f
CTF f6
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f6
);
f6.
setEqn( "prod @3 21600 pixelHeight");
// Create object for f
CTF f7
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f7
);
f7.
setEqn( "sum @0 0 1");
// Create object for f
CTF f8
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f8
);
f8.
setEqn( "prod @6 1 2");
// Create object for f
CTF f9
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f9
);
f9.
setEqn( "prod @7 21600 pixelWidth");
// Create object for f
CTF f10
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f10
);
f10.
setEqn( "sum @8 21600 0");
// Create object for f
CTF f11
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f11
);
f11.
setEqn( "prod @7 21600 pixelHeight");
// Create object for f
CTF f12
= vmlObjectFactory.
createCTF();
formulas.
getF().
add( f12
);
f12.
setEqn( "sum @10 21600 0");
// Create object for path (wrapped in JAXBElement)
CTPath path
= vmlObjectFactory.
createCTPath();
JAXBElement
<org.
docx4j.
vml.
CTPath> pathWrapped
= vmlObjectFactory.
createPath(path
);
shapetype.
getEGShapeElements().
add( pathWrapped
);
path.
setGradientshapeok(org.
docx4j.
vml.
STTrueFalse.
T);
path.
setConnecttype(org.
docx4j.
vml.
officedrawing.
STConnectType.
RECT);
path.
setExtrusionok(org.
docx4j.
vml.
officedrawing.
STTrueFalse.
F);
org.
docx4j.
vml.
officedrawing.
ObjectFactory vmlofficedrawingObjectFactory
= new org.
docx4j.
vml.
officedrawing.
ObjectFactory();
// Create object for lock (wrapped in JAXBElement)
CTLock lock
= vmlofficedrawingObjectFactory.
createCTLock();
JAXBElement
<org.
docx4j.
vml.
officedrawing.
CTLock> lockWrapped
= vmlofficedrawingObjectFactory.
createLock(lock
);
shapetype.
getEGShapeElements().
add( lockWrapped
);
lock.
setAspectratio(org.
docx4j.
vml.
officedrawing.
STTrueFalse.
T);
lock.
setExt(org.
docx4j.
vml.
STExt.
EDIT);
shapetype.
setStroked(org.
docx4j.
vml.
STTrueFalse.
F);
shapetype.
setFilled(org.
docx4j.
vml.
STTrueFalse.
F);
shapetype.
setSpt( new Float(75.0
) );
shapetype.
setConnectortype(org.
docx4j.
vml.
officedrawing.
STConnectorType.
STRAIGHT);
shapetype.
setPreferrelative(org.
docx4j.
vml.
officedrawing.
STTrueFalse.
T);
shapetype.
setPath( "m@4@5l@4@11@9@11@9@5xe");
shapetype.
setCoordsize( "21600,21600");
shapetype.
setVmlId( "_x0000_t75");
shapetype.
setHralign(org.
docx4j.
vml.
officedrawing.
STHrAlign.
LEFT);
shapetype.
setInsetmode(org.
docx4j.
vml.
officedrawing.
STInsetMode.
CUSTOM);
// Create object for shape (wrapped in JAXBElement)
CTShape shape
= vmlObjectFactory.
createCTShape();
JAXBElement
<org.
docx4j.
vml.
CTShape> shapeWrapped
= vmlObjectFactory.
createShape(shape
);
object.
getAnyAndAny().
add( shapeWrapped
);
shape.
setVmlId( "_x0000_i1025");
shape.
setType( "#_x0000_t75");
shape.
setStyle( "width:108.3pt;height:20.75pt");
// Create object for imagedata (wrapped in JAXBElement)
CTImageData imagedata
= vmlObjectFactory.
createCTImageData();
JAXBElement
<org.
docx4j.
vml.
CTImageData> imagedataWrapped
= vmlObjectFactory.
createImagedata(imagedata
);
shape.
getEGShapeElements().
add( imagedataWrapped
);
imagedata.
setId( "rId4");
imagedata.
setTitle( "");
shape.
setHralign(org.
docx4j.
vml.
officedrawing.
STHrAlign.
LEFT);
shape.
setInsetmode(org.
docx4j.
vml.
officedrawing.
STInsetMode.
CUSTOM);
shape.
setConnectortype(org.
docx4j.
vml.
officedrawing.
STConnectorType.
STRAIGHT);
shape.
setOle( "");
Parsed in 0.032 seconds, using
GeSHi 1.0.8.4