Method Signatures and Parameters | |
Jt.selectbox(String label, List<T> options) | label (String) A short label explaining to the user what this selection is for. Markdown is supported, see options (List<T>) The list of options to choose from |
Chainable builder methods | |
index(Integer index) | The index of the preselected option on first render. If |
formatFunction(function.Function<T, String> formatFunction) | Function to modify the display of the options. The |
help(String help) | A tooltip that gets displayed next to the widget label. If |
onChange(function.Consumer<T> onChange) | An optional callback invoked when the selectbox value changes. The value passed to the callback is the previous value of the component. |
disabled(boolean disabled) | Disables the selectbox if set to true. When disabled, users cannot interact with the widget. |
labelVisibility(JtComponent.LabelVisibility labelVisibility) | The visibility of the label. The default is |
width(String width) | The width of the element. This can be one of the following:
|
width(int widthPixels) | The width of the selectbox 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. |
placeholder(String placeholder) | Text displayed when no option is selected. Default varies based on widget configuration. |
acceptNewOptions(boolean acceptNewOptions) | Whether the user can add a selection that isn't included in options.
If this is When a user enters a new item, it is returned by the widget as a string. The new item is not added to the widget's drop-down menu. Jeamlit will use a case-insensitive match from options before adding a new item.
Only compatible with selectbox of |
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 |
use(JtContainer container) | Put the widget in the app, in the provided container. |
Returns after .use() | |
(Nullable T) | The current Nullable T value of the component. |
Examples
Simple dropdown selection
import tech.catheu.jeamlit.core.Jt;
import java.util.List;
public class SelectBoxApp {
public static void main(String[] args) {
String country = Jt.selectbox("Select your country",
List.of("United States", "Canada", "United Kingdom", "Germany", "France")).use();
if (country != null) {
Jt.text("Selected country: " + country).use();
}
}
}
Dropdown with default value
import tech.catheu.jeamlit.core.Jt;
public class ProcessingSelectBoxApp {
public static void main(String[] args) {
String priority = Jt.selectbox("Task priority",
List.of("Low", "Medium", "High", "Critical"))
.index(1)
.use();
Jt.text("Priority: " + priority).use();
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.