CheckBoxField Class
A check box form field in a PDF document.
Declaration
public class CheckBoxField extends FormField
Remarks
The following code snippet creates a checkbox field:
import com.devexpress.drawing.*;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.DXPaperKind;
import java.nio.channels.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument pdfDocument = new PdfDocument()) {
// Add an A4 page to the document.
Page page = pdfDocument.getPages().add(DXPaperKind.A4);
float y = 750;
float step = 30;
float textHeight = 14f;
// Create a check box field and add it to the field collection.
CheckBoxField agreeField = new CheckBoxField("AgreeToTerms");
pdfDocument.getFields().add(agreeField);
// Bind the check box field to a widget and place it on the page.
RectangleF agreeBounds = new RectangleF(50, y - textHeight + 6, 18, 18);
CheckBoxWidgetAnnotation agreeWidget = new CheckBoxWidgetAnnotation(agreeField, agreeBounds);
page.getAnnotations().add(agreeWidget);
y -= step;
// Add a label for the check box field.
TextFragment label = new TextFragment();
label.setText("Agree to terms");
label.setLocation(new PointF(
agreeBounds.getX() + 30,
agreeBounds.getY() + 6));
page.getFragments().add(label);
// Save the document.
try (WritableByteChannel channel =
FileChannel.open(Path.of("result.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(channel);
}
}
}
}
Refer to the following help topic for additional information: Create a Checkbox.
Inherited Members
Inheritance
CheckBoxField(String name)
Initializes a new instance of the CheckBoxField class with specified settings.
Declaration
public CheckBoxField(String name)
Parameters
| Name | Type | Description |
|---|---|---|
| name | String | The name of the check box field. |
Methods
getChecked() Method
Returns whether the check box is selected.
Declaration
public boolean getChecked()
Returns
| Type | Description |
|---|---|
| boolean |
|
getOnStateValue() Method
Returns the value associated with the selected state.
Declaration
public String getOnStateValue()
Returns
| Type | Description |
|---|---|
| String | The value associated with the selected state. |
getShouldGeneratePressedAppearance() Method
Returns whether a pressed appearance is generated for the check box.
Declaration
public boolean getShouldGeneratePressedAppearance()
Returns
| Type | Description |
|---|---|
| boolean |
|
getValue() Method
Returns the current value of the check box field.
Declaration
public String getValue()
Returns
| Type | Description |
|---|---|
| String | The current value of the check box field. |
setChecked(boolean value) Method
Sets whether the check box is selected.
Declaration
public void setChecked(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setOnStateValue(String value) Method
Sets the value associated with the selected state.
Declaration
public void setOnStateValue(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The value associated with the selected state (for example, “Yes”, “On”, or “True”). |
setShouldGeneratePressedAppearance(boolean value) Method
Sets whether to generate a pressed appearance that appears in a checkbox when the mouse button is pressed within the checkbox area.
Declaration
public void setShouldGeneratePressedAppearance(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setValue(String value) Method
Sets the current value of the check box field.
Declaration
public void setValue(String value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | String | The value to assign to the check box field. |