Class CheckBox

All Implemented Interfaces:
Component, Interactable, TextGUIElement

public class CheckBox extends AbstractInteractableComponent<CheckBox>
The checkbox component looks like a regular checkbox that you can find in modern graphics user interfaces, a label and a space that the user can toggle on and off by using enter or space keys.
  • Field Details

  • Constructor Details

    • CheckBox

      public CheckBox()
      Creates a new checkbox with no label, initially set to un-checked
    • CheckBox

      public CheckBox(String label)
      Creates a new checkbox with a specific label, initially set to un-checked
      Parameters:
      label - Label to assign to the check box
  • Method Details

    • setChecked

      public CheckBox setChecked(boolean checked)
      Programmatically updated the check box to a particular checked state
      Parameters:
      checked - If true, the check box will be set to toggled on, otherwise false
      Returns:
      Itself
    • isChecked

      public boolean isChecked()
      Returns the checked state of this check box
      Returns:
      true if the check box is toggled on, otherwise false
    • handleKeyStroke

      public Interactable.Result handleKeyStroke(KeyStroke keyStroke)
      Description copied from class: AbstractInteractableComponent
      This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface, handleInput(..) is final in AbstractInteractableComponent to ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.
      Overrides:
      handleKeyStroke in class AbstractInteractableComponent<CheckBox>
      Parameters:
      keyStroke - What input was entered by the user
      Returns:
      Result of processing the key-stroke
    • setLabel

      public CheckBox setLabel(String label)
      Updates the label of the checkbox
      Parameters:
      label - New label to assign to the check box
      Returns:
      Itself
    • getLabel

      public String getLabel()
      Returns the label of check box
      Returns:
      Label currently assigned to the check box
    • addListener

      public CheckBox addListener(CheckBox.Listener listener)
      Adds a listener to this check box so that it will be notificed on certain user actions
      Parameters:
      listener - Listener to fire events on
      Returns:
      Itself
    • removeListener

      public CheckBox removeListener(CheckBox.Listener listener)
      Removes a listener from this check box so that, if it was previously added, it will no long receive any events
      Parameters:
      listener - Listener to remove from the check box
      Returns:
      Itself
    • createDefaultRenderer

      protected CheckBox.CheckBoxRenderer createDefaultRenderer()
      Description copied from class: AbstractComponent
      When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.
      Specified by:
      createDefaultRenderer in class AbstractInteractableComponent<CheckBox>
      Returns:
      Renderer to use when sizing and drawing this component