Display a multi-line text input widget.

Method Signatures and Parameters

Jt.textArea(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 initial text value when the widget renders. Defaults to empty string. If null, will initialize empty and return null until the user provides input.

height(String height)

The text area widget height. This can be "content", "stretch", or a pixel value. Minimum height is 2 lines.

height(int heightInPixels)

The text area widget height in pixels. Minimum height is 2 lines.

maxChars(Integer maxChars)

The maximum number of characters allowed in the text area.

help(String help)

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

placeholder(String placeholder)

The text displayed when the text area is empty.

disabled(boolean disabled)

Disable the text area 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.

width(String width)

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 function that will be called when the text area 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 area

 import tech.catheu.jeamlit.core.Jt;

 public class TextAreaApp {
     public static void main(String[] args) {
         String feedback = Jt.textArea("Your feedback").use();

         if (!feedback.isEmpty()) {
             Jt.text("Thank you for your feedback!").use();
             Jt.text("Character count: " + feedback.length()).use();
         }
     }
 }

Text area for code input

 import tech.catheu.jeamlit.core.Jt;

 public class CodeTextAreaApp {
     public static void main(String[] args) {
         String code = Jt.textArea("Enter your Java code")
                         .height(200)
                         .placeholder("public class MyClass {\n    // Your code here\n}")
                         .use();

         if (!code.isEmpty()) {
             Jt.text("Code preview:").use();
             Jt.code(code).language("java").use();
         }
     }
 }

forum

Still have questions?

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