StatusLine

StatusLine is the line a screen's actions write their results to, colored by kind (info, success, warning, error) and empty until shown.

Last updated

On this page

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#

Test it#

Rendered as [status status] SUCCESS Saved, or [status status] while empty.

See also#