Skip to main content

RadioGroupField Class

A radio button group form field in a PDF document.

Declaration

public class RadioGroupField extends FormField

Remarks

The following code snippet creates a radio button group with three options:

package barcodes;

import com.devexpress.drawing.*;
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);

            float y = 750;
            float step = 30;
            float textHeight = 14f;

            // Create a radio button group and add it to the field collection.
            RadioGroupField radioGroupField = new RadioGroupField("radioGroup");
            pdfDocument.getFields().add(radioGroupField);

            // Add the first radio button widget and its label.
            RectangleF radioBounds1 = new RectangleF(50, y - textHeight + 6, 18, 18);
            RadioGroupItemWidgetAnnotation radioButton1 =
                    new RadioGroupItemWidgetAnnotation(radioGroupField, "Option1", radioBounds1);
            page.getAnnotations().add(radioButton1);

            TextFragment label1 = new TextFragment();
            label1.setText("Option 1");
            label1.setLocation(new PointF(radioBounds1.getX() + 30, radioBounds1.getY() + 6));
            page.getFragments().add(label1);

            y -= step;

            // Add the second radio button widget and its label.
            RectangleF radioBounds2 = new RectangleF(50, y - textHeight + 6, 18, 18);
            RadioGroupItemWidgetAnnotation radioButton2 =
                    new RadioGroupItemWidgetAnnotation(radioGroupField, "Option2", radioBounds2);
            page.getAnnotations().add(radioButton2);

            TextFragment label2 = new TextFragment();
            label2.setText("Option 2");
            label2.setLocation(new PointF(radioBounds2.getX() + 30, radioBounds2.getY() + 6));
            page.getFragments().add(label2);

            y -= step;

            // Add the third radio button widget and its label.
            RectangleF radioBounds3 = new RectangleF(50, y - textHeight + 6, 18, 18);
            RadioGroupItemWidgetAnnotation radioButton3 =
                    new RadioGroupItemWidgetAnnotation(radioGroupField, "Option3", radioBounds3);
            page.getAnnotations().add(radioButton3);

            TextFragment label3 = new TextFragment();
            label3.setText("Option 3");
            label3.setLocation(new PointF(radioBounds3.getX() + 30, radioBounds3.getY() + 6));
            page.getFragments().add(label3);

            // Select the third radio button by default.
            radioGroupField.setValue("Option3");

            // 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 Radio Button Group.

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
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
FormField
RadioGroupField

RadioGroupField(String name)

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

Declaration

public RadioGroupField(String name)

Parameters

Name Type Description
name String

The name of the radio button group.

Methods

getButtonStyle() Method

Returns the style used to draw the radio buttons.

Declaration

public FormFieldButtonStyle getButtonStyle()

Returns

Type Description
FormFieldButtonStyle

The radio button style.

getShouldGeneratePressedAppearance() Method

Returns whether a pressed appearance is generated for radio buttons.

Declaration

public boolean getShouldGeneratePressedAppearance()

Returns

Type Description
boolean

true if a pressed appearance is generated for radio buttons; otherwise, false.

getValue() Method

Returns the value of the selected radio button.

Declaration

public String getValue()

Returns

Type Description
String

The value of the selected radio button.

setButtonStyle(FormFieldButtonStyle value) Method

Sets the style used to draw the radio buttons.

Declaration

public void setButtonStyle(FormFieldButtonStyle value)

Parameters

Name Type Description
value FormFieldButtonStyle

The radio button style.

setShouldGeneratePressedAppearance(boolean value) Method

Sets whether a pressed appearance is generated for radio buttons.

Declaration

public void setShouldGeneratePressedAppearance(boolean value)

Parameters

Name Type Description
value boolean

true to generate a pressed appearance for radio buttons; otherwise, false.

setValue(String value) Method

Sets the selected radio button by value.

Declaration

public void setValue(String value)

Parameters

Name Type Description
value String

The value of the radio button to select.