Display a numeric input widget.

Method Signatures and Parameters

Jt.numberInput(String label)

label (String)

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

Jt.numberInput(String label, Class<T> valueClass)

label (String)

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


valueClass (Class<T>)

The number type class (Integer, Double, Float, etc.)

Chainable builder methods

value(T value)

The value of this widget when it first renders. If null, initializes with no value and returns null until an input is provided to the component. The default behavior is to return the minimum value. If the minimum value is not set, the widget initializes with a value of 0.

minValue(T minValue)

The minimum permitted value. For Integer and Long, defaults to the corresponding minimum possible value. For Float and Double, no minimum by default.

maxValue(T maxValue)

The maximum permitted value. For Integer and Long, defaults to the corresponding maximum possible value. For Float and Double, no maximum by default.

step(T step)

The stepping interval. Defaults to 1 for Integer and Long, 0.01 for floating points. Must be strictly positive.

format(String format)

A printf-style format string controlling how numbers are displayed in the interface. The output must be purely numeric. This does not impact the return value of the widget. For more information about the formatting specification, see sprintf.js.

For example, format="%0.1f" adjusts the displayed decimal precision to only show one digit after the decimal.

help(String help)

A tooltip that gets displayed next to the widget label. If null, no tooltip is displayed.

placeholder(String placeholder)

An optional text displayed when the number input is empty, providing guidance to the user. If None, no placeholder is displayed.

disabled(boolean disabled)

Disables the number 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)

The width of the element. This can be one of the following:

  • stretch: The width of the element matches the width of the parent container.
  • An integer specifying the width in pixels: The element has 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.

width(int widthPixels)

The width of the number input 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<T> onChange)

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

(T)

The current T value of the component.

Examples

Simple number input

 import tech.catheu.jeamlit.core.Jt;

 public class NumberInputApp {
     public static void main(String[] args) {
         Number quantity = Jt.numberInput("Quantity").minValue(1).maxValue(100).use();

         if (quantity != null) {
             Jt.text("You selected: " + quantity).use();
         }
     }
 }

Integer input with specific type

 import tech.catheu.jeamlit.core.Jt;

 public class TypedNumberInputApp {
     public static void main(String[] args) {
         Integer age = Jt.numberInput("Age", Integer.class)
                         .minValue(0)
                         .maxValue(150)
                         .use();

         if (age != null) {
             String category = age < 18 ? "Minor" : age < 65 ? "Adult" : "Senior";
             Jt.text("Category: " + category).use();
         }
     }
 }

forum

Still have questions?

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