RadioGroupItemWidgetAnnotation Class
A widget annotation for an item in a radio button group.
Declaration
public class RadioGroupItemWidgetAnnotation extends WidgetAnnotation
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
Inheritance
RadioGroupItemWidgetAnnotation(RadioGroupField group, String value, RectangleF bounds)
Initializes a new instance of the RadioGroupItemWidgetAnnotation class with specified settings.
Declaration
public RadioGroupItemWidgetAnnotation(RadioGroupField group, String value, RectangleF bounds)
Parameters
| Name | Type | Description |
|---|---|---|
| group | RadioGroupField | The radio button group associated with the widget annotation. |
| value | String | The value associated with this radio button item. |
| bounds | RectangleF | The bounds of the widget annotation on the page. |
Methods
getButtonStyle() Method
Returns the style used to draw this radio button.
Declaration
public FormFieldButtonStyle getButtonStyle()
Returns
| Type | Description |
|---|---|
| FormFieldButtonStyle | The radio button style. |
getGroup() Method
Returns a radio button group associated with this widget annotation.
Declaration
public RadioGroupField getGroup()
Returns
| Type | Description |
|---|---|
| RadioGroupField | The radio button group associated with this widget annotation. |
getSelected() Method
Returns whether this radio button item is selected.
Declaration
public boolean getSelected()
Returns
| Type | Description |
|---|---|
| boolean |
|
getValue() Method
Returns a value associated with this radio button item.
Declaration
public String getValue()
Returns
| Type | Description |
|---|---|
| String | The value associated with this radio button item. |
setButtonStyle(FormFieldButtonStyle value) Method
Sets the style used to draw this radio button.
Declaration
public void setButtonStyle(FormFieldButtonStyle value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | FormFieldButtonStyle | The radio button style. |
setSelected(boolean value) Method
Sets whether this radio button item is selected.
Declaration
public void setSelected(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|