label
label is an HTML component that creates a caption for a component.
-
XML element:
label -
Java class:
Label
Basics
The label component is applicable to native HTML components and can also serve as an alternative for the label attribute that is present in the majority of UI components in Jmix.
To set a label on a component, pass that component’s id to the setFor attribute of the label. For example, to set the label on a checkbox component:
<div>
<checkbox id ="checkbox"/>
<label text="Enable Notifications" setFor="checkbox"/>
</div>
Having the label associated with a component makes the label text correctly interpreted by assistive technologies, such as screen readers.
To add text that is not associated to a component, use the span or div components.
Dynamic Label
To dynamically set or update text in label, first specify its id attribute:
<label id="dynamicLabel" setFor="button"/>
<button id="button" text="Click"/>
Use this id to reference the label in the view controller and update the text with the setText() method:
@ViewComponent
private Label dynamicLabel;
@Subscribe("button")
public void onButtonClick(final ClickEvent<JmixButton> event) {
dynamicLabel.setText("Button clicked " + event.getClickCount() + " times.");
}
Attributes
id - classNames - colspan - enabled - height - maxHeight - maxWidth - minHeight - minWidth - setFor - text - themeNames - title - visible - whiteSpace - width
themeNames
Adds a theme to the component. Possible values are:
-
normal -
success -
error -
contrast -
primary -
small -
pill
Handlers
|
Чтобы сгенерировать заглушку обработчика в Jmix Studio, используйте вкладку Handlers панели инспектора Jmix UI, или команду Generate Handler, доступную на верхней панели контроллера экрана и через меню Code → Generate (Alt+Insert / Cmd+N). |
See Also
See MDN Docs for more information.