Method Signatures and Parameters | |
Jt.radio(String label, List<T> options) | label (String) A short label explaining to the user what this radio 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 radio 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 radio button's value changes. The value passed to the callback is the previous value of the component. |
disabled(boolean disabled) | Disables the radio buttons if set to true. When disabled, users cannot interact with the widget. |
horizontal(boolean horizontal) | Orients the radio group horizontally instead of vertically when set to true. |
captions(List<String> captions) | A list of captions to show below each radio button. If |
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 radio group 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. |
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 radio selection
import tech.catheu.jeamlit.core.Jt;
import java.util.List;
public class RadioApp {
public static void main(String[] args) {
String size = Jt.radio("Select size",
List.of("Small", "Medium", "Large")).use();
if (size != null) {
Jt.text("Selected size: " + size).use();
}
}
}
Radio with custom objects
import tech.catheu.jeamlit.core.Jt;
public class ProductRadioApp {
public static void main(String[] args) {
record Product(String name, double price) {}
Product selected = Jt
.radio("Choose product",
List.of(new Product("Basic Plan", 9.99),
new Product("Pro Plan", 19.99),
new Product("Enterprise Plan", 49.99)))
.formatFunction(e -> e.name + " ($" + e.price + ")")
.use();
if (selected != null) {
Jt.text("You chose: " + selected.name()).use();
Jt.text("Price: $" + selected.price()).use();
}
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.