com.aspose.words
Class OptionButtonControl

java.lang.Object
  extended by OleControl
      extended by Forms2OleControl
          extended by MorphDataControl
              extended by com.aspose.words.OptionButtonControl

public class OptionButtonControl 
extends MorphDataControl

The OptionButton control enables a single choice in a limited set of mutually exclusive choices.

Example:

Shows how to select radio button.
Document doc = new Document(getMyDir() + "Radio buttons.docx");

Shape shape1 = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
OptionButtonControl optionButton1 = (OptionButtonControl)shape1.getOleFormat().getOleControl();
// Deselect selected first item.
optionButton1.setSelected(false);

Shape shape2 = (Shape)doc.getChild(NodeType.SHAPE, 1, true);
OptionButtonControl optionButton2 = (OptionButtonControl)shape2.getOleFormat().getOleControl();
// Select second option button.
optionButton2.setSelected(true);

Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton1.getType());
Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton2.getType());

doc.save(getArtifactsDir() + "Shape.SelectRadioControl.docx");

Property Getters/Setters Summary
java.awt.ColorgetBackColor()→ inherited from Forms2OleControl
voidsetBackColor(java.awt.Color value)
           Gets or sets a background color of the control. The default value depends on a type of the control.
java.lang.StringgetCaption()→ inherited from Forms2OleControl
           Gets Caption property of control. Default value is an empty string.
Forms2OleControlCollectiongetChildNodes()→ inherited from Forms2OleControl
           Gets collection of immediate child controls.
booleangetEnabled()→ inherited from Forms2OleControl
           Returns true if control is in enabled state.
java.awt.ColorgetForeColor()→ inherited from Forms2OleControl
voidsetForeColor(java.awt.Color value)
           Gets or sets a foreground color of the control. The default value depends on a type of the control.
java.lang.StringgetGroupName()→ inherited from Forms2OleControl
voidsetGroupName(java.lang.String value)
           Gets or sets a string that specifies a group of mutually exclusive controls. The default value is an empty string.
doublegetHeight()→ inherited from Forms2OleControl
voidsetHeight(double value)
           Gets or sets a height of the control in points.
booleanisForms2OleControl()→ inherited from OleControl
           Returns true if the control is a Forms2OleControl.
java.lang.StringgetName()→ inherited from OleControl
voidsetName(java.lang.String value)
           Gets or sets name of the ActiveX control.
booleangetSelected()
voidsetSelected(boolean value)
           Gets or sets a boolean value indicating either this OptionButtonControl is selected or not.
intgetType()
           Gets type of Forms 2.0 control. The value of the property is Forms2OleControlType integer constant.
java.lang.StringgetValue()→ inherited from Forms2OleControl
           Gets underlying Value property which often represents control state. For example checked option button has '1' value while unchecked has '0'. Default value is an empty string.
doublegetWidth()→ inherited from Forms2OleControl
voidsetWidth(double value)
           Gets or sets a width of the control in points.
 

Property Getters/Setters Detail

getBackColor/setBackColor

→ inherited from Forms2OleControl
public java.awt.Color getBackColor() / public void setBackColor(java.awt.Color value)
Gets or sets a background color of the control. The default value depends on a type of the control.

Example:

Shows how to set properties for ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Forms2OleControl oleControl = (Forms2OleControl)shape.getOleFormat().getOleControl();
oleControl.setForeColor(new Color((0x17), (0xE1), (0x35)));
oleControl.setBackColor(new Color((0x33), (0x97), (0xF4)));
oleControl.setHeight(100.54);
oleControl.setWidth(201.06);

getCaption

→ inherited from Forms2OleControl
public java.lang.String getCaption()
Gets Caption property of control. Default value is an empty string.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getChildNodes

→ inherited from Forms2OleControl
public Forms2OleControlCollection getChildNodes()
Gets collection of immediate child controls. Returns null if this control can not have children.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getEnabled

→ inherited from Forms2OleControl
public boolean getEnabled()
Returns true if control is in enabled state.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getForeColor/setForeColor

→ inherited from Forms2OleControl
public java.awt.Color getForeColor() / public void setForeColor(java.awt.Color value)
Gets or sets a foreground color of the control. The default value depends on a type of the control.

Example:

Shows how to set properties for ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Forms2OleControl oleControl = (Forms2OleControl)shape.getOleFormat().getOleControl();
oleControl.setForeColor(new Color((0x17), (0xE1), (0x35)));
oleControl.setBackColor(new Color((0x33), (0x97), (0xF4)));
oleControl.setHeight(100.54);
oleControl.setWidth(201.06);

getGroupName/setGroupName

→ inherited from Forms2OleControl
public java.lang.String getGroupName() / public void setGroupName(java.lang.String value)
Gets or sets a string that specifies a group of mutually exclusive controls. The default value is an empty string.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getHeight/setHeight

→ inherited from Forms2OleControl
public double getHeight() / public void setHeight(double value)
Gets or sets a height of the control in points.

Example:

Shows how to set properties for ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Forms2OleControl oleControl = (Forms2OleControl)shape.getOleFormat().getOleControl();
oleControl.setForeColor(new Color((0x17), (0xE1), (0x35)));
oleControl.setBackColor(new Color((0x33), (0x97), (0xF4)));
oleControl.setHeight(100.54);
oleControl.setWidth(201.06);

isForms2OleControl

→ inherited from OleControl
public boolean isForms2OleControl()
Returns true if the control is a Forms2OleControl.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getName/setName

→ inherited from OleControl
public java.lang.String getName() / public void setName(java.lang.String value)
Gets or sets name of the ActiveX control.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getSelected/setSelected

public boolean getSelected() / public void setSelected(boolean value)
Gets or sets a boolean value indicating either this OptionButtonControl is selected or not. Note, this property allows you to select multiple items in a group of OptionButtonControl with the same GroupName. It is up to you to take care of deselecting a previously selected item when you make this OptionButtonControl selected.

Example:

Shows how to select radio button.
Document doc = new Document(getMyDir() + "Radio buttons.docx");

Shape shape1 = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
OptionButtonControl optionButton1 = (OptionButtonControl)shape1.getOleFormat().getOleControl();
// Deselect selected first item.
optionButton1.setSelected(false);

Shape shape2 = (Shape)doc.getChild(NodeType.SHAPE, 1, true);
OptionButtonControl optionButton2 = (OptionButtonControl)shape2.getOleFormat().getOleControl();
// Select second option button.
optionButton2.setSelected(true);

Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton1.getType());
Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton2.getType());

doc.save(getArtifactsDir() + "Shape.SelectRadioControl.docx");

getType

public int getType()
Gets type of Forms 2.0 control. The value of the property is Forms2OleControlType integer constant.

Example:

Shows how to select radio button.
Document doc = new Document(getMyDir() + "Radio buttons.docx");

Shape shape1 = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
OptionButtonControl optionButton1 = (OptionButtonControl)shape1.getOleFormat().getOleControl();
// Deselect selected first item.
optionButton1.setSelected(false);

Shape shape2 = (Shape)doc.getChild(NodeType.SHAPE, 1, true);
OptionButtonControl optionButton2 = (OptionButtonControl)shape2.getOleFormat().getOleControl();
// Select second option button.
optionButton2.setSelected(true);

Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton1.getType());
Assert.assertEquals(Forms2OleControlType.OPTION_BUTTON, optionButton2.getType());

doc.save(getArtifactsDir() + "Shape.SelectRadioControl.docx");

getValue

→ inherited from Forms2OleControl
public java.lang.String getValue()
Gets underlying Value property which often represents control state. For example checked option button has '1' value while unchecked has '0'. Default value is an empty string.

Example:

Shows how to verify the properties of an ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape) doc.getChild(NodeType.SHAPE, 0, true);
OleControl oleControl = shape.getOleFormat().getOleControl();

Assert.assertEquals(oleControl.getName(), "CheckBox1");

if (oleControl.isForms2OleControl()) {
    Forms2OleControl checkBox = (Forms2OleControl) oleControl;
    Assert.assertEquals(checkBox.getCaption(), "First");
    Assert.assertEquals(checkBox.getValue(), "0");
    Assert.assertEquals(checkBox.getEnabled(), true);
    Assert.assertEquals(checkBox.getType(), Forms2OleControlType.CHECK_BOX);
    Assert.assertEquals(checkBox.getChildNodes(), null);
}

getWidth/setWidth

→ inherited from Forms2OleControl
public double getWidth() / public void setWidth(double value)
Gets or sets a width of the control in points.

Example:

Shows how to set properties for ActiveX control.
Document doc = new Document(getMyDir() + "ActiveX controls.docx");

Shape shape = (Shape)doc.getChild(NodeType.SHAPE, 0, true);
Forms2OleControl oleControl = (Forms2OleControl)shape.getOleFormat().getOleControl();
oleControl.setForeColor(new Color((0x17), (0xE1), (0x35)));
oleControl.setBackColor(new Color((0x33), (0x97), (0xF4)));
oleControl.setHeight(100.54);
oleControl.setWidth(201.06);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.