Skip to main content

ListBoxField Class

A list box form field in a PDF document.

Declaration

public class ListBoxField extends ChoiceField

Remarks

The following code snippet creates a list 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 list box field.
            ListBoxField field = new ListBoxField("Country");

            // Add list items.
            field.getItems().add(new ChoiceFieldItem("USA"));
            field.getItems().add(new ChoiceFieldItem("Canada"));
            field.getItems().add(new ChoiceFieldItem("Germany"));
            field.getItems().add(new ChoiceFieldItem("France"));
            field.getItems().add(new ChoiceFieldItem("UK"));
            field.getItems().add(new ChoiceFieldItem("Italy"));
            field.getItems().add(new ChoiceFieldItem("Spain"));

            pdfDocument.getFields().add(field);

            // Bind the field to a widget.
            ListBoxWidgetAnnotation widget =
                    new ListBoxWidgetAnnotation(
                            field,
                            new RectangleF(20, 640, 120, 70));

            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 List 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

ListBoxField(String name)

Initializes a new instance of the ListBoxField class with specified settings.

Declaration

public ListBoxField(String name)

Parameters

Name Type Description
name String

The name of the list box field.

Methods

addItem(String displayValue, String exportValue) Method

Adds an item to the list box with specified display and export values.

Declaration

public void addItem(String displayValue, String exportValue)

Parameters

Name Type Description
displayValue String

The new item’s text.

exportValue String

The value exported for the new item.

addItem(String displayValue) Method

Adds an item to the list box.

Declaration

public void addItem(String displayValue)

Parameters

Name Type Description
displayValue String

The new item’s text.

clearSelection() Method

Clears the current selection in the list box.

Declaration

public void clearSelection()

getMultiSelect() Method

Returns whether the list box allows multiple selected items.

Declaration

public boolean getMultiSelect()

Returns

Type Description
boolean

true if the list box allows multiple selected items; otherwise, false.

getSelectedValues() Method

Returns export values of selected list box items.

Declaration

public List<String> getSelectedValues()

Returns

Type Description
java.util.List<java.lang.String>

Export values of selected list box items.

getTopIndex() Method

Returns the index of the top visible item in the list box.

Declaration

public int getTopIndex()

Returns

Type Description
int

The index of the top visible item in the list box.

selectValue(String exportValue) Method

Selects the list box item with the specified export value.

Declaration

public boolean selectValue(String exportValue)

Parameters

Name Type Description
exportValue String

The export value of the item to select.

Returns

Type Description
boolean

true if an item with the specified export value was found and selected; otherwise, false.

setMultiSelect(boolean value) Method

Sets whether to allow multiple item selection.

Declaration

public void setMultiSelect(boolean value)

Parameters

Name Type Description
value boolean

true to allow multiple item selection; otherwise, false.

setSelected(int index, boolean value) Method

Sets the selection state of the list box item at the specified index.

Declaration

public void setSelected(int index, boolean value)

Parameters

Name Type Description
index int

The zero-based index of the item.

value boolean

true to select the item; otherwise, false.

setSelectedValues(List<String> value) Method

Sets selected list box items by their export values.

Declaration

public void setSelectedValues(List<String> value)

Parameters

Name Type Description
value java.util.List<java.lang.String>

Export values of items to select.

setTopIndex(int value) Method

Sets the index of the top visible item in the list box.

Declaration

public void setTopIndex(int value)

Parameters

Name Type Description
value int

The index of the top visible item.