Skip to main content

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
JavaObject

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

true if users can enter a custom value in the combo box; otherwise, false.

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

true to allow users to enter a custom value in the combo box; otherwise, false.

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.