ListBoxValueCollection Class
A collection of values selected in a list box field.
Declaration
public class ListBoxValueCollection extends TrackedObjectCollection<String>
Remarks
Call the ListBoxField.getSelectedValues() method to get export values of selected list box items. Call the ListBoxField.setSelectedValues(value) method to specify the values.
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: Read and Modify PDF Form Field Values.
Example: Select Multiple Values in a List Box Field
The following code snippet creates a multi-select list box field, selects two items, and displays export values of the selected items:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
public class Main {
public static void main(String[] args) throws Exception {
try (PdfDocument document = new PdfDocument()) {
Page page = document.getPages().add(595, 842);
ListBoxField listBox = new ListBoxField("Colors");
listBox.setMultiSelect(true);
listBox.getItems().add(new ChoiceFieldItem("Red", "R"));
listBox.getItems().add(new ChoiceFieldItem("Green", "G"));
listBox.getItems().add(new ChoiceFieldItem("Blue", "B"));
document.getFields().add(listBox);
page.getAnnotations().add(new ListBoxWidgetAnnotation(listBox, new RectangleF(50, 650, 150, 60)));
listBox.selectValue("R");
listBox.selectValue("B");
for (String value : listBox.getSelectedValues())
System.out.println(value);
Files.createDirectories(Path.of("output"));
try (OutputStream stream = Files.newOutputStream(Path.of("output", "Document.pdf"))) {
document.save(stream);
}
}
}
}
Inherited Members
Inheritance
Constructors
ListBoxValueCollection() Constructor
Initializes a new instance of the ListBoxValueCollection class.
Declaration
public ListBoxValueCollection()
ListBoxValueCollection(Iterable<String> values) Constructor
Initializes a new instance of the ListBoxValueCollection class with the specified values.
Declaration
public ListBoxValueCollection(Iterable<String> values)
Parameters
| Name | Type | Description |
|---|---|---|
| values | java.lang.Iterable<java.lang.String> | Export values to add to the collection. |
Exceptions
| Type | Description |
|---|---|
| ArgumentNullException | Thrown if the |
Methods
getSource() Method
Returns the internal collection that stores collection items.
Declaration
public ListBoxValueCollection getSource()
Returns
| Type | Description |
|---|---|
| com.devexpress.docs.pdf.internal.ListBoxValueCollection | 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.
objectClone() Method
Returns a copy of the collection.
Declaration
public ListBoxValueCollection objectClone()
Returns
| Type | Description |
|---|---|
ListBoxValueCollection |
A new collection that contains the same values. |