Skip to main content

ChoiceFieldItemCollection Class

A collection of items in a combo box or list box field.

Declaration

public class ChoiceFieldItemCollection extends TrackedObjectCollection<ChoiceFieldItem>

Remarks

Call the ChoiceField.getItems() method to access items of a ComboBoxField or ListBoxField.

The collection implements the java.util.List interface and does not accept null items. If you add or insert a null item or replace an item with null, the API throws an ArgumentNullException. If you pass an index outside the collection bounds, the API throws an ArgumentOutOfRangeException.

Refer to the following help topic for additional information: Create PDF Forms.

Example

Create a Combo Box Field

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 a 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);
            }
        }
    }
}

Inherited Members

com.devexpress.java.internal.collections.JListAdapter.add(T)
com.devexpress.java.internal.collections.JListAdapter.add(int,T)
com.devexpress.java.internal.collections.JListAdapter.clear()
com.devexpress.java.internal.collections.JListAdapter.contains(java.lang.Object)
com.devexpress.java.internal.collections.JListAdapter.get(int)
com.devexpress.java.internal.collections.JListAdapter.indexOf(java.lang.Object)
com.devexpress.java.internal.collections.JListAdapter.remove(int)
com.devexpress.java.internal.collections.JListAdapter.remove(java.lang.Object)
com.devexpress.java.internal.collections.JListAdapter.set(int,T)
com.devexpress.java.internal.collections.JListAdapter.size()
java.lang.Object.clone()
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)
java.util.AbstractCollection.<T>toArray(T[])
java.util.AbstractCollection.addAll(java.util.Collection<? extends E>)
java.util.AbstractCollection.containsAll(java.util.Collection<?>)
java.util.AbstractCollection.isEmpty()
java.util.AbstractCollection.removeAll(java.util.Collection<?>)
java.util.AbstractCollection.retainAll(java.util.Collection<?>)
java.util.AbstractCollection.toArray()
java.util.AbstractCollection.toString()
java.util.AbstractList.add(E)
java.util.AbstractList.add(int,E)
java.util.AbstractList.addAll(int,java.util.Collection<? extends E>)
java.util.AbstractList.equals(java.lang.Object)
java.util.AbstractList.hashCode()
java.util.AbstractList.iterator()
java.util.AbstractList.lastIndexOf(java.lang.Object)
java.util.AbstractList.listIterator()
java.util.AbstractList.listIterator(int)
java.util.AbstractList.removeRange(int,int)
java.util.AbstractList.set(int,E)
java.util.AbstractList.subList(int,int)

Inheritance

Object
java.util.AbstractCollection
java.util.AbstractList
JListAdapter
TrackedObjectCollection<T>
ChoiceFieldItemCollection

Constructors

ChoiceFieldItemCollection() Constructor

Initializes a new instance of the ChoiceFieldItemCollection class.

Declaration

public ChoiceFieldItemCollection()

ChoiceFieldItemCollection(Iterable<ChoiceFieldItem> items) Constructor

Initializes a new instance of the ChoiceFieldItemCollection class with the specified items.

Declaration

public ChoiceFieldItemCollection(Iterable<ChoiceFieldItem> items)

Parameters

Name Type Description
items java.lang.Iterable<ChoiceFieldItem>

Items to add to the collection.

Exceptions

Type Description
ArgumentNullException

Thrown if the items collection contains a null item.

Methods

getSource() Method

Returns the internal collection that stores collection items.

Declaration

public ChoiceFieldItemCollection getSource()

Returns

Type Description
com.devexpress.docs.pdf.internal.ChoiceFieldItemCollection

The internal collection.

Remarks

The getSource() method supports the internal infrastructure of the PDF Document API. Do not call the getSource() method in your code.