Insert a single-element container.
Insert a container into your app that can be used to hold a single element. This allows you to, for example, remove elements at any point, or replace several elements at once (using a child multi-element container).
To insert/replace/clear an element on the returned container:
var container = Jt.empty("empty-1").use();
Jt.yourElement().use(container);
See examples below.
Method Signatures and Parameters | |
Jt.empty() | |
Chainable builder methods | |
height(Integer height) | The height of the container in pixels. When a fixed height is specified, the container will enable scrolling if content exceeds the specified height. It is recommended to use scrolling containers sparingly and avoid heights that exceed 500 pixels for optimal mobile experience. |
border(Boolean border) | Whether to show a border around the container. If not specified ( |
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() | |
(JtContainer) | The current JtContainer value of the component. |
Examples
Dynamic content replacement
import tech.catheu.jeamlit.core.Jt;
import java.util.List;
public class EmptyApp {
public static void main(String[] args) {
var placeholder = Jt.empty().use();
String selected = Jt.selectbox("Choose content",
List.of("None", "Text", "Button")).use();
switch (selected) {
case "Text" -> Jt.text("Dynamic text content").use(placeholder);
case "Button" -> {
if (Jt.button("Dynamic button").use(placeholder)) {
Jt.text("Button clicked!").use();
}
}
// case "None" -> container remains empty
}
}
}
Simple animations
import io.jeamlit.core.Jt;import tech.catheu.jeamlit.core.Jt;
public class AnimationEmptyApp {
public static void main(String[] args) {
var emptyContainer = Jt.empty().use();
for (i = 10; i>=1; i--) {
Jt.text(i + "!").use(emptyContainer);
Thread.sleep(1000);
}
Jt.text("Happy new Year !").use(emptyContainer);
Jt.button("rerun").use();
}
}
Still have questions?
Go to our discussions forum for helpful information and advice from Jeamlit experts.