ComboBoxField Class
A combo box form field in a PDF document.
Declaration
public class ComboBoxField extends ChoiceField
Remarks
The following code snippet creates a combo box field:
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);
// Create a combo box field.
ComboBoxField field =
new ComboBoxField("Country");
// Add list items.
field.getItems().add(new ChoiceFieldItem("USA"));
field.getItems().add(new ChoiceFieldItem("Canada"));
field.getItems().add(new ChoiceFieldItem("Germany"));
// Select the default value.
field.setValue("USA");
pdfDocument.getFields().add(field);
// Bind the field to a widget.
ComboBoxWidgetAnnotation widget =
new ComboBoxWidgetAnnotation(field, new RectangleF(20, 700, 120, 24));
page.getAnnotations().add(widget);
// 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 Combo Box.
Inherited Members
Inheritance
ComboBoxField(String name)
Initializes a new instance of the ComboBoxField class with specified settings.
Declaration
public ComboBoxField(String name)
Parameters
| Name | Type | Description |
|---|---|---|
| name | String | The name of the combo box field. |
Methods
getEditable() Method
Returns whether users can enter a custom value in the combo box.
Declaration
public boolean getEditable()
Returns
| Type | Description |
|---|---|
| boolean |
|
getValueFormat() Method
Returns formatting and validation settings for combo box values.
Declaration
public FormFieldValueFormat getValueFormat()
Returns
| Type | Description |
|---|---|
| FormFieldValueFormat | Formatting and validation settings for combo box values. |
setEditable(boolean value) Method
Sets whether users can enter a custom value in the combo box.
Declaration
public void setEditable(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setValueFormat(FormFieldValueFormat value) Method
Sets formatting and validation settings for combo box values.
Declaration
public void setValueFormat(FormFieldValueFormat value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FormFieldValueFormat | Formatting and validation settings for combo box values. |