Radio Button
- Common Properties
- Font-specific Properties
- Other Common Properties
- Property Propagation Between Model and Control
- Common Workflow to add Controls
- The Example Listings
- Label Field
- Command Button
- Image Control
- Check Box
- Radio Button
- Scroll Bar
- List Box
- Combo Box
- Progress Bar
- Horizontal/Vertical Line Control
- Group Box
- Text Field
- Text Field Extensions
- Formatted Field
- Numeric Field
- Currency Field
- Date Field
- Time Field
- Pattern Field
- Roadmap Control
- File Control
- File Picker
- Message Box
A radio button control model com.sun.star.awt.UnoControlRadioButtonModel is a simple switch with two states selected by the user. Usually these controls are used in groups to display several options that the user may select. While they are very similar to check boxes, selecting one radio button deselects all the radio buttons in the same group. To assemble several radio buttons to a control group it is important to know that there may not be any control TabIndex
between the tab indices of the radio buttons although it is not necessary for the tab indices to be directly consecutive. Two groups of radio buttons can be separated by any control with a tab index that is between the tab indices of the two groups. Usually a group box, or horizontal and vertical lines are used because those controls visually group the radio buttons together. In principal, any control can be used to separate groups of radio buttons. There is no functional relationship between a radio button and a group box Group Box. The state of an radio button is accessed by the State property in the service com.sun.star.awt.UnoControlRadioButtonModel, where 0 is not checked and 1 is checked.
A radio button may also display images similar to a button as described in Command Button.
The following example demonstrates the way a group of two radio buttons may be created. Note the assignment of the tab indices to each radio button.
public void insertRadioButtonGroup(short _nTabIndex, int _nPosX, int _nPosY, int _nWidth){ try{ // create a unique name by means of an own implementation... String sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton"); // create a controlmodel at the multiservicefactory of the dialog model... Object oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); XMultiPropertySet xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xRBMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "State", "TabIndex", "Width" } , new Object[] {new Integer(8), "~First Option", sName, new Integer(_nPosX), new Integer(_nPosY), new Short((short) 1), new Short(_nTabIndex++),new Integer(_nWidth)}); // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oRBModel); // create a unique name by means of an own implementation... sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton"); oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xRBMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width" } , new Object[] {new Integer(8), "~Second Option", sName, new Integer(130), new Integer(214), new Short(_nTabIndex), new Integer(150)}); // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oRBModel); }catch (com.sun.star.uno.Exception ex){ /* perform individual exception handling here. * Possible exception types are: * com.sun.star.lang.IllegalArgumentException, * com.sun.star.lang.WrappedTargetException, * com.sun.star.container.ElementExistException, * com.sun.star.beans.PropertyVetoException, * com.sun.star.beans.UnknownPropertyException, * com.sun.star.uno.Exception */ ex.printStackTrace(System.out); }}
Content on this page is licensed under the Public Documentation License (PDL). |