Class Checkbox

java.lang.Object
dev.xichil.mvui.Entry
dev.xichil.mvui.Checkbox

public final class Checkbox extends Entry
A check box with its label to the right, like vanilla's Checkbox (1.16+; older versions get an equivalent drawing). Holds the same kind of value as a Toggle, drawn differently: use check boxes for lists of independent yes/no choices ("include: [x] options [ ] keybinds [x] servers"), a toggle for settings.
Checkbox.builder("includeKeys")
        .label(Text.translatable("mymod.includeKeys", "Include key bindings"))
        .value(() -> export.includeKeys)
        .onChange(checked -> export.includeKeys = checked)
        .build();

The value lives in the mod, as with a toggle. Required: label, value, onChange. Can't be in a MenuScreen's footer.

  • Method Details

    • builder

      public static Checkbox.Builder builder(String id)
      Starts building a check box.
      Parameters:
      id - the check box's id, unique within its screen
      Returns:
      a new builder
      Throws:
      IllegalArgumentException - if id is invalid
    • label

      public Text label()
      The text to the right of the box, from the mod's supplier.
      Returns:
      the text drawn to the right of the box
    • checked

      public boolean checked()
      Whether the box is checked: the mod's current value, from its value supplier.
      Returns:
      true if the box is checked
    • set

      public void set(boolean checked)
      Passes checked to onChange, even if it equals the current value.
      Parameters:
      checked - the new value
    • toggle

      public void toggle()
      Passes the opposite of checked() to onChange, as a click does.
    • accept

      public <R> R accept(EntryVisitor<R> visitor)
      Description copied from class: Entry
      Calls the EntryVisitor method for this entry's type (visitButton for a Button, …) and returns its result. A Section visits as its header, a NumberField as its TextInput.
      Specified by:
      accept in class Entry
      Type Parameters:
      R - the visitor's result type
      Parameters:
      visitor - the visitor, usually a backend's widget factory
      Returns:
      what the visitor returned