Checkbox
Checkbox is a check box with its label beside it, for lists of independent yes/no choices such as what to include in an export.
A check box with its label to the right. It holds the same kind of value as a Toggle, drawn differently: use check boxes for lists of independent yes/no choices, a toggle for settings.
Checkbox.builder("includeKeys")
.label(Text.translatable("mymod.includeKeys", "Include key bindings"))
.value(() -> export.includeKeys)
.onChange(checked -> export.includeKeys = checked)
.build();
Builder#
| Method | Required | Default | Notes |
|---|---|---|---|
label(Supplier<Text>) / label(Text) |
yes | the text to the right of the box | |
value(BooleanSupplier) |
yes | whether it is checked; re-read on every refresh | |
onChange(Consumer<Boolean>) |
yes | stores the new state; main thread | |
enabled, tooltip, visible |
no | options every widget has |
Behaviour#
- A click calls
onChangewith the opposite ofvalue; the box shows the new state only ifvaluereturns it. - From 1.16 it is vanilla's own check box; older versions get an equivalent drawing.
- Footer: no.
Test it#
host.click("includeKeys");
Rendered as [checkbox includeKeys] [x] Include key bindings, or [ ] while unchecked.
See also#
- Javadoc: Checkbox