Display a button widget.

Method Signatures and Parameters

Jt.button(String label)

label (String)

A short label explaining to the user what this button is for. Markdown is supported, see Jt#markdown(String) for more details.

Chainable builder methods

type(String type)

The button appearance type. Can be "primary", "secondary" (default), or "tertiary".

icon(String icon)

An icon to display with the error message. The following values are valid:

  • A single-character emoji. For example: 🔥. Emoji short codes are not supported.
  • An icon from the Material Symbols library (rounded style) in the format :icon_name: where icon_name is the name of the icon in snake case. For example: :search:. See full list of icons here.
If null (default), no icon is displayed.

help(String help)

A tooltip that gets displayed when the button is hovered over.

disabled(boolean disabled)

Disable the button if set to true. When disabled, users cannot interact with the widget.

useContainerWidth(boolean useContainerWidth)

Makes the button fill the width of its container if set to true.

onClick(function.Consumer<Boolean> onClick)

An optional callback invoked when this button is clicked. The value passed to the callback is the previous value of the component.

key(String key)

A string to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. No two widgets may have the same key.

No description

use()

Put the widget in the app, in the MAIN container.

use(JtContainer container)

Put the widget in the app, in the provided container.

Returns after .use()

(boolean)

The current boolean value of the component.

Examples

Basic button usage and interaction

 import tech.catheu.jeamlit.core.Jt;

 public class ButtonApp {
     public static void main(String[] args) {
         if (Jt.button("Say hello").use()) {
             Jt.text("Why hello there").use();
         } else {
             Jt.text("Goodbye").use();
         }
     }
 }

forum

Still have questions?

Go to our discussions forum for helpful information and advice from Jeamlit experts.