public class CheckBox
ImplementsActionSource<ActionEvent>, Animation, Editable, IconHolder, ReleasableComponent, SelectableIconHolder, StyleListener, TextHolder
CheckBox is a button that can be selected or deselected and displays
its state to the user. Check out com.codename1.ui.RadioButton for
a more exclusive selection approach. Both components support a toggle button
mode using the com.codename1.ui.Button#setToggle(boolean) API.
Form hi = new Form("Test CheckBox", 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 CheckBox(String text) | Constructs a checkbox with the given text |
public CheckBox() | Constructs a checkbox with no text |
public CheckBox(Image icon) | Constructs a checkbox with the given icon |
public CheckBox(String text, Image icon) | Constructs a checkbox with the given text and icon |
Methods
public static CheckBox createToggle(String text, Image icon) | Shorthand for creating the check box setting the icon/text and making it into a toggle button |
public static CheckBox createToggle(String text) | Shorthand for creating the check box setting the icon/text and making it into a toggle button |
public static CheckBox createToggle(Image icon) | Shorthand for creating the check box setting the icon/text and making it into a toggle button |
public boolean isSelected() | Return true if the checkbox is selected |
public void setSelected(boolean selected) | Selects the current checkbox |
public void released(int x, int y) | Invoked to change the state of the button to the released state |
protected void fireActionEvent(int x, int y) | Allows subclasses to override action event behavior for pointer coordinates. |
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. |
protected String paramString() | Returns a string representing the state of this component. |
public void refreshTheme(boolean merge) | Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME! |
public boolean isOppositeSide() | Places the check box on the opposite side at the far end |
public void setOppositeSide(boolean oppositeSide) | Places the check 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, initLaf, getText, getIcon, setIcon, getVerticalAlignment, setVerticalAlignment, getAlignment, getTextPosition, setTextPosition, getGap, setGap, 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, toString, 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
CheckBox
public CheckBox(String text)Parameters
textString- to display next to the checkbox
CheckBox
public CheckBox()CheckBox
public CheckBox(Image icon)Parameters
iconImage- icon to display next to the checkbox
CheckBox
public CheckBox(String text, Image icon)Parameters
textString- to display next to the checkbox
iconImage- icon to display next to the text
Method details
createToggle
public static CheckBox createToggle(String text, Image icon)Parameters
textString- the text for the button
iconImage- the icon for the button
Returns
createToggle
public static CheckBox createToggle(String text)Parameters
textString- the text for the button
Returns
createToggle
public static CheckBox createToggle(Image icon)Parameters
iconImage- the icon for the button
Returns
isSelected
public boolean isSelected()Returns
setSelected
public void setSelected(boolean selected)Parameters
selectedboolean- value for selection
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
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)
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
calcPreferredSize
protected Dimension calcPreferredSize()Returns
paramString
protected String paramString()null.Returns
refreshTheme
public void refreshTheme(boolean merge)Parameters
mergeboolean- indicates if the current styles should be merged with the new styles
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)