StatusLine
StatusLine is the line a screen's actions write their results to, colored by kind (info, success, warning, error) and empty until shown.
A line the screen's actions write their results to, such as "Loaded 'default'" or "Couldn't write the file". It is empty until a message is shown, and backends color the text by its kind.
StatusLine status = StatusLine.builder("status").build();
Button save = Button.builder("save")
.label(Text.translatable("mymod.save", "Save"))
.onPress(() -> host.runAsync(() -> {
store.save();
return null;
}, (ignored, error) -> {
if (error != null) {
status.show(StatusLine.Kind.ERROR, Text.translatable("mymod.save.failed", "Save failed: %s",
Text.literal(String.valueOf(error.getMessage()))));
} else {
status.show(StatusLine.Kind.SUCCESS, Text.translatable("mymod.saved", "Saved"));
}
}))
.build();
MenuScreen.builder("main").title(title).add(status).add(save).build();
Builder#
StatusLine.builder(id).build(). There are no required fields; enabled, tooltip and visible work as on
every widget.
Methods#
| Method | Does |
|---|---|
show(Kind, Text) |
shows a message, replacing the previous one. Throws IllegalStateException on null. |
clear() |
empties the line and resets the kind to INFO |
text() |
the current message, or null while empty |
kind() |
the current kind; INFO while empty |
StatusLine.Kind |
For |
|---|---|
INFO |
neutral information |
SUCCESS |
the action worked |
WARNING |
something to notice, or a partial failure |
ERROR |
the action failed |
Behaviour#
- Keep a reference to the built status line, so actions can write to it.
- Unlike other widgets it has no supplier: the message is state of the entry and stays until replaced.
showandclearare safe from any thread. The message appears on the next refresh, which happens by itself after an action or arunAsynccallback; elsewhere callhost.refresh().- A
ConfirmDialog's answer runs after the dialog closes, so it can write to the status line of the screen that opened it. - Footer: yes.
Test it#
Rendered as [status status] SUCCESS Saved, or [status status] while empty.
See also#
- Javadoc: StatusLine
- Slow work: files and network