Button

Button runs an action when clicked - saving, resetting, or opening another screen - and is the usual Done entry in a screen's footer.

Last updated

On this page

A push button, drawn as the version's vanilla button. Use it for actions, and in the footer for Done.

Button.builder("details")
        .label(Text.translatable("mymod.details", "Details..."))
        .onPress(() -> host.open(detailsScreen(host)))
        .build();

Button.builder("done").label(UiTexts.DONE).onPress(host::back).build();

Builder#

Method Required Default Notes
label(Supplier<Text>) / label(Text) yes the text on the button
onPress(Runnable) yes runs on the main thread when clicked
enabled, tooltip, visible no options every widget has

Behaviour#

Test it#

host.click("details");                 // presses it

Rendered as [button details] Details....

See also#