public class RadioButton extends Button
RadioButton is a Button
that maintains a selection state exclusively
within a specific ButtonGroup
. Check out CheckBox
for
a looser selection approach. Both components support a toggle button
mode using the Button.setToggle(boolean)
API.
STATE_DEFAULT, STATE_PRESSED, STATE_ROLLOVER
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 and 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
|
Modifier and Type | Method and 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
|
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
|
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
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
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, drop, focusGained, focusLost, getAbsoluteX, getAbsoluteY, 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, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, longKeyPress, longPointerPress, onScrollX, onScrollY, 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, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, repaint, repaint, requestFocus, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, 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, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, toImage, updateNativeOverlay, visibleBoundsContains
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
getGap, getIcon, getIconStyleComponent, getIconUIID, getTextPosition, setFontIcon, setGap, setIcon, setIconUIID, setMaterialIcon, setTextPosition
public RadioButton(String text)
text
- to display next to the buttonpublic RadioButton()
public RadioButton(Image icon)
icon
- icon to show next to the buttonpublic static RadioButton createToggle(String text, Image icon, ButtonGroup bg)
text
- the text for the buttonicon
- the icon for the buttonbg
- the button grouppublic static RadioButton createToggle(String text, ButtonGroup bg)
text
- the text for the buttonbg
- the button grouppublic static RadioButton createToggle(Image icon, ButtonGroup bg)
icon
- the icon for the buttonbg
- the button grouppublic static RadioButton createToggle(Command cmd, ButtonGroup bg)
cmd
- the commandbg
- the button groupprotected void initLaf(UIManager uim)
protected void fireActionEvent(int x, int y)
fireActionEvent
in class Button
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)public String toString()
public boolean isSelected()
isSelected
in class Button
public void setSelected(boolean selected)
selected
- value for selectionpublic boolean isUnselectAllowed()
public void setUnselectAllowed(boolean unselectAllowed)
unselectAllowed
- true to allow deselection of a radio button, false for the default behaviorpublic void released(int x, int y)
public void paint(Graphics g)
protected Dimension calcPreferredSize()
calcPreferredSize
in class Button
public ButtonGroup getButtonGroup()
public void setGroup(String groupName)
groupName
- a name for the gouppublic String getGroup()
public boolean isOppositeSide()
isOppositeSide
in class Button
public void setOppositeSide(boolean oppositeSide)
oppositeSide
- the oppositeSide to setpublic String[] getBindablePropertyNames()
getBindablePropertyNames
in class Label
public Class[] getBindablePropertyTypes()
getBindablePropertyTypes
in class Label
public void bindProperty(String prop, BindTarget target)
bindProperty
in class Label
prop
- the property nametarget
- the target binderpublic void unbindProperty(String prop, BindTarget target)
unbindProperty
in class Label
prop
- the property namestarget
- the target binderpublic Object getBoundPropertyValue(String prop)
getBoundPropertyValue
in class Label
prop
- the propertypublic void setBoundPropertyValue(String prop, Object value)
setBoundPropertyValue
in class Label
prop
- the property whose value should be setvalue
- the valuepublic void addChangeListener(ActionListener l)
l
- Listener to be notified when selected value changes.#removeChangeListener(com.codename1.ui.events.ActionListener)
public void removeChangeListeners(ActionListener l)
l
- addChangeListener(com.codename1.ui.events.ActionListener)