Display a single-line text input widget.

Method Signatures and Parameters

Jt.textInput(String label)

label (String)

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

Chainable builder methods

value(String value)

The text value of this widget when it first renders. Defaults to empty string.

maxChars(Integer maxChars)

The maximum number of characters allowed in the text input.

type(String type)

Can be "default" or "password". Determines if input masks the user's typed value.

help(String help)

A tooltip that gets displayed next to the text. If this is null (default), no tooltip is displayed.

autocomplete(String autocomplete)

An optional value that will be passed to the element's autocomplete property. If unspecified, this value will be set to "new-password" for "password" inputs, and the empty string for "default" inputs. For more details, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete.

placeholder(String placeholder)

An optional string displayed when the text input is empty.

disabled(boolean disabled)

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

labelVisibility(JtComponent.LabelVisibility labelVisibility)

The visibility of the label. The default is VISIBLE. If this is HIDDEN, Jeamlit displays an empty spacer instead of the label, which can help keep the widget aligned with other widgets. If this is COLLAPSED, Jeamlit displays no label or spacer.

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.

width(String width)

Controls the widget width. Can be "stretch" (default) or a pixel value.

width(int widthPixels)

The width of the element in pixels. The element will have a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container.

onChange(function.Consumer<String> onChange)

An optional callback invoked when the text input's value changes. The value passed in 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()

(string)

The current string value of the component.

Examples

Simple text input

 import tech.catheu.jeamlit.core.Jt;

 public class TextInputApp {
     public static void main(String[] args) {
         String name = Jt.textInput("Your name").use();

         if (!name.isEmpty()) {
             Jt.text("Hello, " + name + "!").use();
         }
     }
 }

Text input with validation

 import tech.catheu.jeamlit.core.Jt;

 public class ValidatedTextInputApp {
     public static void main(String[] args) {
         String email = Jt.textInput("Email address")
                          .placeholder("Enter your email")
                          .use();

         if (!email.isEmpty() && !email.contains("@")) {
             Jt.error("Please enter a valid email address").use();
         } else if (!email.isEmpty()) {
             Jt.text("Valid email: " + email).use();
         }
     }
 }

forum

Still have questions?

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