# Class RadioButton

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Label
com.codename1.ui.Button
com.codename1.ui.RadioButton

All Implemented Interfaces:
  `Animation, Editable, ActionSource<ActionEvent>, StyleListener, IconHolder, ReleasableComponent, SelectableIconHolder, TextHolder`

public class RadioButton extends Button

RadioButton is a `Button` that maintains a selection state exclusively within a specific `ButtonGroup`. Check out `com.codename1.ui.CheckBox` for a looser selection approach. Both components support a toggle button mode using the `com.codename1.ui.Button#setToggle(boolean)` API.

    Form hi = new Form("Test RadioButton", BoxLayout.y());

    Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "CheckBox", 3.0f);

    CheckBox cb1 = new CheckBox("CheckBox No Icon");
    cb1.setSelected(true);
    CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
    CheckBox cb3 = new CheckBox("CheckBox Opposite True", icon);
    CheckBox cb4 = new CheckBox("CheckBox Opposite False", icon);
    cb3.setOppositeSide(true);
    cb4.setOppositeSide(false);
    RadioButton rb1 = new RadioButton("Radio 1");
    RadioButton rb2 = new RadioButton("Radio 2");
    RadioButton rb3 = new RadioButton("Radio 3", icon);
    new ButtonGroup(rb1, rb2, rb3);
    rb2.setSelected(true);
    hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
    hi.show();

- ## Field Summary

  ### Fields inherited from class Button

  `STATE_DEFAULT, STATE_PRESSED, STATE_ROLLOVER`

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RadioButton()`
  Creates an empty radio button
  `RadioButton(Image icon)`
  Constructs a radio with the given icon
  `RadioButton(String text)`
  Constructs a radio with the given text
  `RadioButton(String text, Image icon)`
  Constructs a radio with the given text and icon

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addChangeListener(ActionListener l)`
  Adds a listener to be notified when the the checkbox's selected value changes.
  `void`
  `bindProperty(String prop, BindTarget target)`
  Binds the given property name to the given bind target
  `protected Dimension`
  `calcPreferredSize()`
  Calculates the preferred size based on component content.
  `static RadioButton`
  `createToggle(Command cmd, ButtonGroup bg)`
  Shorthand for creating the radio button, adding it to a group, setting the command and making it into a toggle button
  `static RadioButton`
  `createToggle(Image icon, ButtonGroup bg)`
  Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button
  `static RadioButton`
  `createToggle(String text, ButtonGroup bg)`
  Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button
  `static RadioButton`
  `createToggle(String text, Image icon, ButtonGroup bg)`
  Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button
  `protected void`
  `fireActionEvent(int x, int y)`
  Allows subclasses to override action event behavior for pointer coordinates.
  `String[]`
  `getBindablePropertyNames()`
  Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound
  `Class[]`
  `getBindablePropertyTypes()`
  Returns the types of the properties that are bindable within this component
  `Object`
  `getBoundPropertyValue(String prop)`
  Allows the binding code to extract the value of the property
  `ButtonGroup`
  `getButtonGroup()`
  Returns the parent button group
  `String`
  `getGroup()`
  This is a helper method to ease the usage of button groups
  `protected void`
  `initLaf(UIManager uim)`
  This method initializes the Component defaults constants
  `boolean`
  `isOppositeSide()`
  Places the radio box on the opposite side at the far end
  `boolean`
  `isSelected()`
  Returns true if the radio button is selected
  `boolean`
  `isUnselectAllowed()`
  Returns true if this RadioButton can be unselected
  `void`
  `paint(Graphics g)`
  This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
  `void`
  `released(int x, int y)`
  Invoked to change the state of the button to the released state
  `void`
  `removeChangeListeners(ActionListener l)`
  Removes a change change listener.
  `void`
  `setBoundPropertyValue(String prop, Object value)`
  Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!
  `void`
  `setGroup(String groupName)`
  This is a helper method to ease the usage of button groups
  `void`
  `setOppositeSide(boolean oppositeSide)`
  Places the radio box on the opposite side at the far end
  `void`
  `setSelected(boolean selected)`
  Selects the current radio button
  `void`
  `setUnselectAllowed(boolean unselectAllowed)`
  Allows unselecting a selected RadioButton.
  `String`
  `toString()`
  Overriden to return a useful value for debugging purposes
  `void`
  `unbindProperty(String prop, BindTarget target)`
  Removes a bind target from the given property name

  ### Methods inherited from class Button

  `addActionListener, addStateChangeListener, animate, bindStateTo, dragInitiated, fireClicked, getActionListeners, getBorder, getCommand, getDisabledIcon, getIconFromState, getListeners, getPressedIcon, getReleaseRadius, getRolloverIcon, getRolloverPressedIcon, getState, isAutoRelease, isButtonRippleEffectDefault, isCapsText, isCapsTextDefault, isSelectableInteraction, isToggle, keyPressed, keyReleased, keyRepeated, pointerHover, pointerHoverReleased, pointerPressed, pointerReleased, pressed, released, removeActionListener, removeStateChangeListener, resetFocusable, setAlignment, setAutoRelease, setButtonRippleEffectDefault, setCapsText, setCapsTextDefault, setCommand, setDisabledIcon, setPressedIcon, setReleased, setReleaseRadius, setRolloverIcon, setRolloverPressedIcon, setText, setToggle, setUIID, unbindStateFrom`

  ### Methods inherited from class Label

  `getAlignment, getBadgeStyleComponent, getBadgeText, getBaseline, getBaselineResizeBehavior, getDefaultGap, getFontIcon, getFontIconSize, getGap, getIcon, getIconFont, getIconStyleComponent, getIconUIID, getMask, getMaskedIcon, getMaskName, getMaterialIcon, getMaterialIconSize, getMaxAutoSize, getMinAutoSize, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getShiftMillimeters, getShiftMillimetersF, getShiftText, getStringWidth, getText, getTextPosition, getTextSelectionSupport, getVerticalAlignment, initUnselectedStyle, isAutoSizeMode, isDefaultTickerEnabled, isEndsWith3Points, isLegacyRenderer, isShouldLocalize, isShowEvenIfBlank, isTextSelectionEnabled, isTickerEnabled, isTickerRunning, laidOut, paramString, refreshTheme, setAutoSizeMode, setBadgeText, setBadgeUIID, setDefaultGap, setDefaultTickerEnabled, setEndsWith3Points, setFontIcon, setFontIcon, setFontIcon, setGap, setIcon, setIconUIID, setLegacyRenderer, setMask, setMaskName, setMaterialIcon, setMaterialIcon, setMaxAutoSize, setMinAutoSize, setPropertyValue, setShiftMillimeters, setShiftMillimeters, setShiftText, setShouldLocalize, setShowEvenIfBlank, setTextPosition, setTextSelectionEnabled, setTickerEnabled, setVerticalAlignment, shouldTickerStart, startTicker, startTicker, stopTicker, styleChanged`

  ### Methods inherited from class Component

  `addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStylusListener, announceForAccessibility, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBottomGap, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSideGap, getStyle, getTabIndex, getTensileLength, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHoverPressed, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStylusListener, repaint, repaint, requestFocus, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, toImage, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface IconHolder

  `getGap, getIcon, getIconStyleComponent, getIconUIID, getTextPosition, setFontIcon, setGap, setIcon, setIconUIID, setMaterialIcon, setTextPosition`

- ## Constructor Details

  - ### RadioButton

    public RadioButton(String text)

    Constructs a radio with the given text

    ###### Parameters

    - `text`: to display next to the button

  - ### RadioButton

    public RadioButton()
    Creates an empty radio button

  - ### RadioButton

    public RadioButton(Image icon)

    Constructs a radio with the given icon

    ###### Parameters

    - `icon`: icon to show next to the button

  - ### RadioButton

    public RadioButton(String text, Image icon)

    Constructs a radio with the given text and icon

    ###### Parameters

    - `text`: to display next to the button

    - `icon`: icon to show next to the button

- ## Method Details

  - ### createToggle

    public static RadioButton createToggle(String text, Image icon, ButtonGroup bg)

    Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button

    ###### Parameters

    - `text`: the text for the button

    - `icon`: the icon for the button

    - `bg`: the button group

    ###### Returns

    a radio button

  - ### createToggle

    public static RadioButton createToggle(String text, ButtonGroup bg)

    Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button

    ###### Parameters

    - `text`: the text for the button

    - `bg`: the button group

    ###### Returns

    a radio button

  - ### createToggle

    public static RadioButton createToggle(Image icon, ButtonGroup bg)

    Shorthand for creating the radio button, adding it to a group, setting the icon/text and making it into a toggle button

    ###### Parameters

    - `icon`: the icon for the button

    - `bg`: the button group

    ###### Returns

    a radio button

  - ### createToggle

    public static RadioButton createToggle(Command cmd, ButtonGroup bg)

    Shorthand for creating the radio button, adding it to a group, setting the command and making it into a toggle button

    ###### Parameters

    - `cmd`: the command

    - `bg`: the button group

    ###### Returns

    a radio button

  - ### initLaf

    protected void initLaf(UIManager uim)
    This method initializes the Component defaults constants
    Overrides:
      `initLaf` in class `Label`

  - ### fireActionEvent

    protected void fireActionEvent(int x, int y)

    Allows subclasses to override action event behavior for pointer coordinates.

    ###### Parameters

    - `x`: the x position of the click if applicable (can be 0 or -1 otherwise)

    - `y`: the y position of the click if applicable (can be 0 or -1 otherwise)

    Overrides:
      `fireActionEvent` in class `Button`

  - ### toString

    public String toString()

    Overriden to return a useful value for debugging purposes

    ###### Returns

    a string representation of this component

    Overrides:
      `toString` in class `Component`

  - ### isSelected

    public boolean isSelected()

    Returns true if the radio button is selected

    ###### Returns

    true if the radio button is selected

    Overrides:
      `isSelected` in class `Button`

  - ### setSelected

    public void setSelected(boolean selected)

    Selects the current radio button

    ###### Parameters

    - `selected`: value for selection

  - ### isUnselectAllowed

    public boolean isUnselectAllowed()

    Returns true if this RadioButton can be unselected

    ###### Returns

    true to allow deselection of radio buttons

  - ### setUnselectAllowed

    public void setUnselectAllowed(boolean unselectAllowed)

    Allows unselecting a selected RadioButton. This is useful for when implementing a ButtonGroup that allows no selection or a single selection.,

    ###### Parameters

    - `unselectAllowed`: true to allow deselection of a radio button, false for the default behavior

  - ### released

    public void released(int x, int y)

    Invoked to change the state of the button to the released state

    ###### Parameters

    - `x`: the x position if a touch event triggered this, -1 if this isn't relevant

    - `y`: the y position if a touch event triggered this, -1 if this isn't relevant

    Overrides:
      `released` in class `Button`

  - ### paint

    public void paint(Graphics g)

    This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

    ###### Parameters

    - `g`: the component graphics
    Specified by:
      `paint` in interface `Animation`
    Overrides:
      `paint` in class `Button`

  - ### calcPreferredSize

    protected Dimension calcPreferredSize()

    Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

    ###### Returns

    the calculated preferred size based on component content

    Overrides:
      `calcPreferredSize` in class `Button`

  - ### getButtonGroup

    public ButtonGroup getButtonGroup()

    Returns the parent button group

    ###### Returns

    the parent button group

  - ### getGroup

    public String getGroup()

    This is a helper method to ease the usage of button groups

    ###### Returns

    the name of the group

  - ### setGroup

    public void setGroup(String groupName)

    This is a helper method to ease the usage of button groups

    ###### Parameters

    - `groupName`: a name for the goup

  - ### isOppositeSide

    public boolean isOppositeSide()

    Places the radio box on the opposite side at the far end

    ###### Returns

    the oppositeSide

    Overrides:
      `isOppositeSide` in class `Button`

  - ### setOppositeSide

    public void setOppositeSide(boolean oppositeSide)

    Places the radio box on the opposite side at the far end

    ###### Parameters

    - `oppositeSide`: the oppositeSide to set

  - ### getBindablePropertyNames

    public String[] getBindablePropertyNames()

    Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound

    ###### Returns

    a string array of property names or null

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    Overrides:
      `getBindablePropertyNames` in class `Label`

  - ### getBindablePropertyTypes

    public Class[] getBindablePropertyTypes()

    Returns the types of the properties that are bindable within this component

    ###### Returns

    the class for binding

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    Overrides:
      `getBindablePropertyTypes` in class `Label`

  - ### bindProperty

    public void bindProperty(String prop, BindTarget target)

    Binds the given property name to the given bind target

    ###### Parameters

    - `prop`: the property name

    - `target`: the target binder

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    ###### Deprecated

    uses the deprecated BindTarget interface

    ###### Deprecated

    uses the deprecated BindTarget interface

    Overrides:
      `bindProperty` in class `Label`

  - ### unbindProperty

    public void unbindProperty(String prop, BindTarget target)

    Removes a bind target from the given property name

    ###### Parameters

    - `prop`: the property names

    - `target`: the target binder

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    ###### Deprecated

    uses the deprecated BindTarget interface

    ###### Deprecated

    uses the deprecated BindTarget interface

    Overrides:
      `unbindProperty` in class `Label`

  - ### getBoundPropertyValue

    public Object getBoundPropertyValue(String prop)

    Allows the binding code to extract the value of the property

    ###### Parameters

    - `prop`: the property

    ###### Returns

    the value for the property

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    Overrides:
      `getBoundPropertyValue` in class `Label`

  - ### setBoundPropertyValue

    public void setBoundPropertyValue(String prop, Object value)

    Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!

    ###### Parameters

    - `prop`: the property whose value should be set

    - `value`: the value

    ###### Deprecated

    this mapped to an older iteration of properties that is no longer used

    Overrides:
      `setBoundPropertyValue` in class `Label`

  - ### addChangeListener

    public void addChangeListener(ActionListener l)

    Adds a listener to be notified when the the checkbox's selected value changes. The difference between a change listener and an action listener is that a change listener is fired whenever there is a change, but action events are only fired when the change is a result of the user clicking on the checkbox.

    ###### Parameters

    - `l`: Listener to be notified when selected value changes.

    ###### See also

    - #removeChangeListener(com.codename1.ui.events.ActionListener)

  - ### removeChangeListeners

    public void removeChangeListeners(ActionListener l)

    Removes a change change listener.

    ###### Parameters

    - `l`

    ###### See also

    - #addChangeListener(com.codename1.ui.events.ActionListener)