public class RadioButton
ImplementsActionSource<ActionEvent>, Animation, Editable, IconHolder, ReleasableComponent, SelectableIconHolder, StyleListener, TextHolder
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();
Constructors
public RadioButton(String text) | Constructs a radio with the given text |
public RadioButton() | Creates an empty radio button |
public RadioButton(Image icon) | Constructs a radio with the given icon |
public RadioButton(String text, Image icon) | Constructs a radio with the given text and icon |
Methods
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 |
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 |
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 |
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 |
protected void initLaf(UIManager uim) | This method initializes the Component defaults constants |
protected void fireActionEvent(int x, int y) | Allows subclasses to override action event behavior for pointer coordinates. |
public String toString() | Overriden to return a useful value for debugging purposes |
public boolean isSelected() | Returns true if the radio button is selected |
public void setSelected(boolean selected) | Selects the current radio button |
public boolean isUnselectAllowed() | Returns true if this RadioButton can be unselected |
public void setUnselectAllowed(boolean unselectAllowed) | Allows unselecting a selected RadioButton. |
public void released(int x, int y) | Invoked to change the state of the button to the released state |
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. |
protected Dimension calcPreferredSize() | Calculates the preferred size based on component content. |
public ButtonGroup getButtonGroup() | Returns the parent button group |
public String getGroup() | This is a helper method to ease the usage of button groups |
public void setGroup(String groupName) | This is a helper method to ease the usage of button groups |
public boolean isOppositeSide() | Places the radio box on the opposite side at the far end |
public void setOppositeSide(boolean oppositeSide) | Places the radio box on the opposite side at the far end |
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 |
public Class[] getBindablePropertyTypes() | Returns the types of the properties that are bindable within this component |
public void bindProperty(String prop, BindTarget target) | Deprecated Binds the given property name to the given bind target |
public void unbindProperty(String prop, BindTarget target) | Deprecated Removes a bind target from the given property name |
public Object getBoundPropertyValue(String prop) | Allows the binding code to extract the value of the property |
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! |
public void addChangeListener(ActionListener l) | Adds a listener to be notified when the the checkbox’s selected value changes. |
public void removeChangeListeners(ActionListener l) | Removes a change change listener. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From Button
isCapsTextDefault, setCapsTextDefault, isButtonRippleEffectDefault, setButtonRippleEffectDefault, bindStateTo, unbindStateFrom, resetFocusable, getState, setReleased, getPressedIcon, setPressedIcon, getRolloverPressedIcon, setRolloverPressedIcon, getDisabledIcon, setDisabledIcon, getRolloverIcon, setRolloverIcon, addStateChangeListener, removeStateChangeListener, addActionListener, removeActionListener, getActionListeners, getListeners, getIconFromState, pressed, released, keyPressed, keyReleased, keyRepeated, fireClicked, isSelectableInteraction, pointerHover, pointerHoverReleased, pointerPressed, pointerReleased, dragInitiated, getBorder, getCommand, setCommand, setAlignment, isToggle, setToggle, setUIID, animate, getReleaseRadius, setReleaseRadius, isAutoRelease, setAutoRelease, isCapsText, setCapsText, setText
From Label
getDefaultGap, setDefaultGap, isDefaultTickerEnabled, setDefaultTickerEnabled, laidOut, getBadgeText, setBadgeText, setBadgeUIID, getBadgeStyleComponent, getIconStyleComponent, setFontIcon, setMaterialIcon, setFontIcon, getMaterialIcon, setMaterialIcon, getFontIcon, setFontIcon, getMaterialIconSize, getFontIconSize, getIconFont, getBaselineResizeBehavior, getBaseline, refreshTheme, getText, getIcon, setIcon, getVerticalAlignment, setVerticalAlignment, getAlignment, getTextPosition, setTextPosition, getGap, setGap, paramString, getMaxAutoSize, setMaxAutoSize, getMinAutoSize, setMinAutoSize, getShiftText, setShiftText, shouldTickerStart, startTicker, startTicker, stopTicker, isTickerRunning, isTickerEnabled, setTickerEnabled, isEndsWith3Points, setEndsWith3Points, getMask, setMask, getMaskName, setMaskName, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, getMaskedIcon, isShouldLocalize, setShouldLocalize, getShiftMillimeters, setShiftMillimeters, setShiftMillimeters, getShiftMillimetersF, isShowEvenIfBlank, setShowEvenIfBlank, getStringWidth, isLegacyRenderer, setLegacyRenderer, styleChanged, initUnselectedStyle, isAutoSizeMode, setAutoSizeMode, isTextSelectionEnabled, setTextSelectionEnabled, getTextSelectionSupport, getIconUIID, setIconUIID
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, deinitialize, initComponent, isInitialized, setInitialized, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
RadioButton
public RadioButton(String text)Parameters
textString- to display next to the button
RadioButton
public RadioButton()RadioButton
public RadioButton(Image icon)Parameters
iconImage- icon to show next to the button
RadioButton
public RadioButton(String text, Image icon)Parameters
textString- to display next to the button
iconImage- icon to show next to the button
Method details
createToggle
public static RadioButton createToggle(String text, Image icon, ButtonGroup bg)Parameters
textString- the text for the button
iconImage- the icon for the button
bgButtonGroup- the button group
Returns
createToggle
public static RadioButton createToggle(String text, ButtonGroup bg)Parameters
textString- the text for the button
bgButtonGroup- the button group
Returns
createToggle
public static RadioButton createToggle(Image icon, ButtonGroup bg)Parameters
iconImage- the icon for the button
bgButtonGroup- the button group
Returns
createToggle
public static RadioButton createToggle(Command cmd, ButtonGroup bg)Parameters
cmdCommand- the command
bgButtonGroup- the button group
Returns
initLaf
protected void initLaf(UIManager uim)fireActionEvent
protected void fireActionEvent(int x, int y)Parameters
xint- the x position of the click if applicable (can be 0 or -1 otherwise)
yint- the y position of the click if applicable (can be 0 or -1 otherwise)
toString
public String toString()Returns
isSelected
public boolean isSelected()Returns
setSelected
public void setSelected(boolean selected)Parameters
selectedboolean- value for selection
isUnselectAllowed
public boolean isUnselectAllowed()Returns
setUnselectAllowed
public void setUnselectAllowed(boolean unselectAllowed)Parameters
unselectAllowedboolean- true to allow deselection of a radio button, false for the default behavior
released
public void released(int x, int y)Parameters
xint- the x position if a touch event triggered this, -1 if this isn’t relevant
yint- the y position if a touch event triggered this, -1 if this isn’t relevant
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
calcPreferredSize
protected Dimension calcPreferredSize()Returns
getButtonGroup
public ButtonGroup getButtonGroup()Returns
getGroup
public String getGroup()Returns
setGroup
public void setGroup(String groupName)Parameters
groupNameString- a name for the goup
isOppositeSide
public boolean isOppositeSide()Returns
setOppositeSide
public void setOppositeSide(boolean oppositeSide)Parameters
oppositeSideboolean- the oppositeSide to set
getBindablePropertyNames
public String[] getBindablePropertyNames()Returns
getBindablePropertyTypes
public Class[] getBindablePropertyTypes()Returns
bindProperty
public void bindProperty(String prop, BindTarget target)Parameters
propString- the property name
targetBindTarget- the target binder
unbindProperty
public void unbindProperty(String prop, BindTarget target)Parameters
propString- the property names
targetBindTarget- the target binder
getBoundPropertyValue
public Object getBoundPropertyValue(String prop)Parameters
propString- the property
Returns
setBoundPropertyValue
public void setBoundPropertyValue(String prop, Object value)Parameters
propString- the property whose value should be set
valueObject- the value
addChangeListener
public void addChangeListener(ActionListener l)Parameters
lActionListener- Listener to be notified when selected value changes.
See also
#removeChangeListener(com.codename1.ui.events.ActionListener)
removeChangeListeners
public void removeChangeListeners(ActionListener l)