RadioButtonMenuItem

Radio button menu item UI component that extends MenuItem class.

RadioButton is a component used to select of multiple option by clicking on it. Multiple RadioButton components must be grouped for selection to work as expected. To group them pick one main RadioButtonMenuItem and group other RadioButtonMenuItem with it. For example if you have three RadioButtonMenuItem components that you want to group, you must group second component with first one, then third component with any component that is already grouped (first or second). Then to detect selection changes add onChange(e => {console.log(e.value);}) to only one of the grouped RadioButton components, and e.value will be the value of currently selected RadioButton. See example below.

Constructor

new RadioButtonMenuItem()

Example
// Example how to group RadioButton components and detect when selected value of a group changes.

var fileMenu = new Menu("Options").addTo(menuBar);

// create first RadioButtonMenuItem and sets group value change handler function
mainForm.radio1 = new RadioButtonMenuItem("Option 1").addTo(fileMenu).onChange(e => {console.log(e.value);});

// create second RadioButtonMenuItem and group it with first one
mainForm.radio2 = new RadioButtonMenuItem("Option 2").addTo(fileMenu).groupWith(mainForm.radio1);

// create third RadioButtonMenuItem and group it with first one
mainForm.radio3 = new RadioButtonMenuItem("Option 3").addTo(fileMenu).groupWith(mainForm.radio1);

// now when user clicks on any of these radio buttons a new selected value will be logged in console.

Extends

Members

(readonly) group :Array.<RadioButtonMenuItem>

Retrieves an array of RadioButtonMenuItem components grouped with this component (including this component). Returns an array of minimum one (current) item.

Type:

Methods

clearSelection() → {RadioButtonMenuItem}

Deselect all RadioButtonMenuItem elements grouped with this element.

Returns:

Returns this component.

Type: 
RadioButtonMenuItem

groupWith(componentopt) → {RadioButtonMenuItem}

Adds this RadioButtonMenuItem to the group of another RadioButtonMenuItem, or removes it from its current group.

  • Pass another RadioButtonMenuItem to join its group.
  • Pass null to leave the current group (if any).
Parameters:
NameTypeAttributesDescription
componentRadioButtonMenuItem | null<optional>

A RadioButtonMenuItem to join, or null to leave the current group.

Returns:

This RadioButtonMenuItem, for chaining.

Type: 
RadioButtonMenuItem

keyboardShortcut(keys)

Sets keyboard shortcut (accelerators) to menu item type of components: MenuItem, CheckBoxMenuItem, RadioButtonMenuItem. See examples below. Allows to activate the menu item action using specified keyboard key combination on keyboard. This shortcut is usually display in the right side of the mnu item's text.

Parameters:
NameTypeDescription
keysstring

Key combination as a string. See example how to construct it.

Returns:

String Description of keyboard shortcut

Example
Modifiers: CTRL|CONTROL|SHIFT|ALT|ALTGRAPH|META

Keys: A-Z|0-9|NUMPAD[0-9]|SPACE|INSERT|ESCAPE|F[1-24]|TAB|ADD|SUBTRACT|DELETE|BACK_SPACE|BACK_SLASH|
BRACELEFT|BRACERIGHT|OPEN_BRACKET|CLOSE_BRACKET|SEMICOLON|COMMA|CAPS_LOCK|BACK_QUOTE|MINUS|PERIOD|
UP|DOWN|RIGHT|LEFT|MULTIPLY|DIVIDE|NUM_LOCK|HOME|END|PAGE_UP|PAGE_DOWN|PAUSE|SCROLL_LOCK|WINDOWS|
CONTEXT_MENU|DECIMAL|ENTER

Example key combinations: CTRL+Q, ALT+F1, CTRL+SHIFT+5, CTRL+N4, META+SHIFT+6, DELETE+SHIFT, SHIFT+UP, CTRL+OPEN_BRACKET, ATL+DOWN

menuItem1.keyboardShortcut("CTRL+Q");
menuItemUP.keyboardShortcut("SHIFT+NUMPAD[8]");

mnemonic(keyopt) → {string|MenuItem}

Gets or sets the mnemonic (keyboard shortcut key) for menu item type of components: Menu, MenuItem, CheckBoxMenuItem, RadioButtonMenuItem. Its not same as setting keyboardShortcut(...). A mnemonic allows users to activate the menu item using the keyboard (typically Alt + key).
NOTE: Not all systems and UIs show underline under mnemonic character. Some systems only show it after Alt key was pressed.

Parameters:
NameTypeAttributesDescription
keystring<optional>

A single character representing the mnemonic key (case-insensitive). If omitted, acts as a getter.

Inherited From
Returns:

If called without arguments, returns the current mnemonic key. If a key is provided, sets the mnemonic and returns this MenuItem instance.

Type: 
string | MenuItem
Example
menuItem.text("Quit").mnemonic("q"); // Makes letter Q to be used as the keyboard shortcut key

open(positionopt, invokeropt) → {MenuItem}

Opens this menu item and all of its parent menus or context menu.

Parameters:
NameTypeAttributesDefaultDescription
positionobject<optional>
null

Example: {x: 100, y: 100}. Use only when root ancestor of this item is ContextMenu, to specify position where to position the ContextMenu. If invoker is specified, then position is relative to position of invoker component, otherwise it's a screen position.

invokerobject<optional>
null

Used to set invoker if the context menu isn't assigned to any object and you want to be able to get invoker by using "invoker" getter.

Inherited From
Returns:

Returns this MenuItem instance.

Type: 
MenuItem

selected(selectedopt) → {RadioButtonMenuItem|boolean}

Sets or gets boolean indicating whether this component is selected.

Parameters:
NameTypeAttributesDescription
selectedboolean<optional>

true to select, false to deselect.

Returns:

Returns this CheckBoxMenuItem instance if argument is provided, otherwise returns boolean value.

Type: 
RadioButtonMenuItem | boolean

selectedValue() → {RadioButtonMenuItem|*}

Selects a radio button in the group of this component and has the specified value, or returns the value of selected radio button grouped with this component.

Returns:
Type: 
RadioButtonMenuItem | *

value(valueopt) → {RadioButtonMenuItem|*}

Sets or gets a value of this component.

Parameters:
NameTypeAttributesDescription
value*<optional>

Value to be held by this component

Returns:

If setting a value, then an instance of this component is returned, otherwise current value is returned.

Type: 
RadioButtonMenuItem | *