MultiLineInput
MultiLineInput is a text box of two to twelve lines with word wrap, for notes and descriptions players type freely, validated like TextInput.
A text box of several lines, for notes, descriptions or lists the player types freely. It wraps long lines at the box's width and takes Enter as a line break; text longer than the box scrolls inside it.
MultiLineInput.builder("notes")
.label(Text.translatable("mymod.notes", "Notes"))
.initial(config.notes)
.lines(6)
.maxLength(2000)
.onChange(s -> config.notes = s)
.build();
Builder#
| Method | Required | Default | Notes |
|---|---|---|---|
label(Supplier<Text>) / label(Text) |
yes | the text above the box | |
initial(String) |
no | "" |
line breaks may be \n, \r\n or \r; cut to maxLength; not passed to onChange |
maxLength(int) |
no | 1024 |
the most characters, line breaks included; must be positive |
lines(int) |
no | 4 |
how many lines the box shows at once (its height), from 2 to 12 |
validator(Function<String, Text>) |
no | every text is valid | returns an error, or null |
onChange(Consumer<String>) |
no | does nothing | receives the text after each edit that leaves it valid |
enabled, tooltip, visible |
no | options every widget has |
build() throws if the label is missing, maxLength isn't positive, or lines is outside 2 – 12.
Behaviour#
- Works like a TextInput: the text lives in the entry, the error shows below the box, and
onChangereceives only valid text.value(),isValid(),error()andsetValue(…)are the same. - Line breaks are always
\n, also for pasted\r\n. There is no limit on the number of lines apart frommaxLength. - From 1.19.3 it is vanilla's own multi-line edit box; older versions draw an equivalent box.
- Footer: no.
Test it#
host.type("notes", "first line\nsecond line");
Rendered as [textarea notes] Notes: "first line\nsecond line".
See also#
- Javadoc: MultiLineInput