Class CheckBox

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

public class CheckBox extends Button

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.

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);
  • Constructor Details

    • CheckBox

      public CheckBox(String text)

      Constructs a checkbox with the given text

      Parameters
      • text: to display next to the checkbox
    • CheckBox

      public CheckBox()
      Constructs a checkbox with no text
    • CheckBox

      public CheckBox(Image icon)

      Constructs a checkbox with the given icon

      Parameters
      • icon: icon to display next to the checkbox
    • CheckBox

      public CheckBox(String text, Image icon)

      Constructs a checkbox with the given text and icon

      Parameters
      • text: to display next to the checkbox

      • icon: icon to display next to the text

  • Method Details

    • createToggle

      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

      Parameters
      • text: the text for the button

      • icon: the icon for the button

      Returns

      a check box

    • createToggle

      public static CheckBox createToggle(String text)

      Shorthand for creating the check box setting the icon/text and making it into a toggle button

      Parameters
      • text: the text for the button
      Returns

      a check box

    • createToggle

      public static CheckBox createToggle(Image icon)

      Shorthand for creating the check box setting the icon/text and making it into a toggle button

      Parameters
      • icon: the icon for the button
      Returns

      a check box

    • isSelected

      public boolean isSelected()

      Return true if the checkbox is selected

      Returns

      true if the checkbox is selected

      Overrides:
      isSelected in class Button
    • setSelected

      public void setSelected(boolean selected)

      Selects the current checkbox

      Parameters
      • selected: value for selection
    • 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
    • fireActionEvent

      protected void fireActionEvent(int x, int y)

      Allows subclasses to override action event behavior

      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
    • 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
    • paramString

      protected String paramString()

      Returns a string representing the state of this component. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

      Returns

      a string representation of this component's state

      Overrides:
      paramString in class Label
    • refreshTheme

      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!

      Parameters
      • merge: indicates if the current styles should be merged with the new styles
      Overrides:
      refreshTheme in class Label
    • isOppositeSide

      public boolean isOppositeSide()

      Places the check 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 check 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.
      Since

      6.0

      See also
      • #removeChangeListener(com.codename1.ui.events.ActionListener)
    • removeChangeListeners

      public void removeChangeListeners(ActionListener l)

      Removes a change change listener.

      Parameters
      • l
      Since

      6.0

      See also
      • #addChangeListener(com.codename1.ui.events.ActionListener)