OptionButtonControl

Inheritance: java.lang.Object, com.aspose.words.OleControl, com.aspose.words.Forms2OleControl, com.aspose.words.MorphDataControl

public class OptionButtonControl extends MorphDataControl

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

Examples:

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");
 

Methods

MethodDescription
getBackColor()Gets a background color of the control.
getCaption()Gets a Caption property of the control.
getChildNodes()Gets collection of immediate child controls.
getClsidInternal()
getEnabled()Returns true if control is in enabled state.
getExtensionForUser(String progId)
getFileNameForUser()
getForeColor()Gets a foreground color of the control.
getGroupName()Gets a string that specifies a group of mutually exclusive controls.
getHeight()Gets a height of the control in points.
getId()
getName()Gets name of the ActiveX control.
getSelected()Gets a boolean value indicating either this OptionButtonControl is selected or not.
getType()Gets type of Forms 2.0 control.
getValue()Gets underlying Value property which often represents control state.
getWidth()Gets a width of the control in points.
isEmpty()
isForms2OleControl()Returns true if the control is a Forms2OleControl.
isForms2OleControlInternal()
setBackColor(Color value)Sets a background color of the control.
setCaption(String value)Sets a Caption property of the control.
setForeColor(Color value)Sets a foreground color of the control.
setGroupName(String value)Sets a string that specifies a group of mutually exclusive controls.
setHeight(double value)Sets a height of the control in points.
setId(int value)
setName(String value)Sets name of the ActiveX control.
setSelected(boolean value)Sets a boolean value indicating either this OptionButtonControl is selected or not.
setWidth(double value)Sets a width of the control in points.

getBackColor()

public Color getBackColor()

Gets a background color of the control. The default value depends on a type of the control.

Examples:

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);
 

Returns: java.awt.Color - A background color of the control.

getCaption()

public String getCaption()

Gets a Caption property of the control. Default value is an empty string.

Examples:

Shows how to set caption for ActiveX control.


 DocumentBuilder builder = new DocumentBuilder();

 CommandButtonControl button1 = new CommandButtonControl(); { button1.setCaption("Button caption"); }
 Shape shape = builder.insertForms2OleControl(button1);
 Assert.assertEquals("Button caption", ((Forms2OleControl)shape.getOleFormat().getOleControl()).getCaption());
 

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);
 }
 

Returns: java.lang.String - A Caption property of the control.

getChildNodes()

public Forms2OleControlCollection getChildNodes()

Gets collection of immediate child controls.

Remarks:

Returns null if this control can not have children.

Examples:

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);
 }
 

Returns: Forms2OleControlCollection - Collection of immediate child controls.

getClsidInternal()

public String getClsidInternal()

Returns: java.lang.String

getEnabled()

public boolean getEnabled()

Returns true if control is in enabled state.

Examples:

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);
 }
 

Returns: boolean - true if control is in enabled state.

getExtensionForUser(String progId)

public String getExtensionForUser(String progId)

Parameters:

ParameterTypeDescription
progIdjava.lang.String

Returns: java.lang.String

getFileNameForUser()

public String getFileNameForUser()

Returns: java.lang.String

getForeColor()

public Color getForeColor()

Gets a foreground color of the control. The default value depends on a type of the control.

Examples:

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);
 

Returns: java.awt.Color - A foreground color of the control.

getGroupName()

public String getGroupName()

Gets a string that specifies a group of mutually exclusive controls. The default value is an empty string.

Examples:

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);
 }
 

Returns: java.lang.String - A string that specifies a group of mutually exclusive controls.

getHeight()

public double getHeight()

Gets a height of the control in points.

Examples:

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);
 

Returns: double - A height of the control in points.

getId()

public int getId()

Returns: int

getName()

public String getName()

Gets name of the ActiveX control.

Examples:

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);
 }
 

Returns: java.lang.String - Name of the ActiveX control.

getSelected()

public boolean getSelected()

Gets a boolean value indicating either this OptionButtonControl is selected or not.

Remarks:

Note, this property allows you to select multiple items in a group of OptionButtonControl with the same Forms2OleControl.getGroupName() / Forms2OleControl.setGroupName(java.lang.String). It is up to you to take care of deselecting a previously selected item when you make this OptionButtonControl selected.

Examples:

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");
 

Returns: boolean - A boolean value indicating either this OptionButtonControl is selected or not.

getType()

public int getType()

Gets type of Forms 2.0 control.

Examples:

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");
 

Returns: int - Type of Forms 2.0 control. The returned value is one of Forms2OleControlType constants.

getValue()

public 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.

Examples:

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);
 }
 

Returns: java.lang.String - Underlying Value property which often represents control state.

getWidth()

public double getWidth()

Gets a width of the control in points.

Examples:

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);
 

Returns: double - A width of the control in points.

isEmpty()

public boolean isEmpty()

Returns: boolean

isForms2OleControl()

public boolean isForms2OleControl()

Returns true if the control is a Forms2OleControl.

Examples:

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);
 }
 

Returns: boolean - true if the control is a Forms2OleControl.

isForms2OleControlInternal()

public boolean isForms2OleControlInternal()

Returns: boolean

setBackColor(Color value)

public void setBackColor(Color value)

Sets a background color of the control. The default value depends on a type of the control.

Examples:

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);
 

Parameters:

ParameterTypeDescription
valuejava.awt.ColorA background color of the control.

setCaption(String value)

public void setCaption(String value)

Sets a Caption property of the control. Default value is an empty string.

Examples:

Shows how to set caption for ActiveX control.


 DocumentBuilder builder = new DocumentBuilder();

 CommandButtonControl button1 = new CommandButtonControl(); { button1.setCaption("Button caption"); }
 Shape shape = builder.insertForms2OleControl(button1);
 Assert.assertEquals("Button caption", ((Forms2OleControl)shape.getOleFormat().getOleControl()).getCaption());
 

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);
 }
 

Parameters:

ParameterTypeDescription
valuejava.lang.StringA Caption property of the control.

setForeColor(Color value)

public void setForeColor(Color value)

Sets a foreground color of the control. The default value depends on a type of the control.

Examples:

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);
 

Parameters:

ParameterTypeDescription
valuejava.awt.ColorA foreground color of the control.

setGroupName(String value)

public void setGroupName(String value)

Sets a string that specifies a group of mutually exclusive controls. The default value is an empty string.

Examples:

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);
 }
 

Parameters:

ParameterTypeDescription
valuejava.lang.StringA string that specifies a group of mutually exclusive controls.

setHeight(double value)

public void setHeight(double value)

Sets a height of the control in points.

Examples:

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);
 

Parameters:

ParameterTypeDescription
valuedoubleA height of the control in points.

setId(int value)

public void setId(int value)

Parameters:

ParameterTypeDescription
valueint

setName(String value)

public void setName(String value)

Sets name of the ActiveX control.

Examples:

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);
 }
 

Parameters:

ParameterTypeDescription
valuejava.lang.StringName of the ActiveX control.

setSelected(boolean value)

public void setSelected(boolean value)

Sets a boolean value indicating either this OptionButtonControl is selected or not.

Remarks:

Note, this property allows you to select multiple items in a group of OptionButtonControl with the same Forms2OleControl.getGroupName() / Forms2OleControl.setGroupName(java.lang.String). It is up to you to take care of deselecting a previously selected item when you make this OptionButtonControl selected.

Examples:

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");
 

Parameters:

ParameterTypeDescription
valuebooleanA boolean value indicating either this OptionButtonControl is selected or not.

setWidth(double value)

public void setWidth(double value)

Sets a width of the control in points.

Examples:

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);
 

Parameters:

ParameterTypeDescription
valuedoubleA width of the control in points.