@Tag(value="label") public class Label extends HtmlContainer
<label>
element, which represents a
caption for an item in a user interface.
Note that Label components are not meant for loose text in the page - they
should be coupled with another component by using the
setFor(Component)
or by adding them to it with the
HasComponents.add(Component...)
method.
Clicking on a label automatically transfers the focus to the associated
component. This is especially helpful when building forms with
Input
s.
For adding texts to the page without linking them to other components,
consider using a Span
or a Div
instead.
Constructor and Description |
---|
Label()
Creates a new empty label.
|
Label(String text)
Creates a new label with the given text content.
|
Modifier and Type | Method and Description |
---|---|
Optional<String> |
getFor()
Gets the id of the component that this label describes.
|
void |
setFor(Component forComponent)
Sets the component that this label describes.
|
void |
setFor(String forId)
Sets the id of the component that this label describes.
|
getTitle, setTitle
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
isEnabled, setEnabled
getElement
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addAttachListener
addDetachListener
public Label()
public Label(String text)
text
- the text contentpublic void setFor(Component forComponent)
The provided component must have an id set. This component will still use the old id if the id of the provided component is changed after this method has been called.
forComponent
- the component that this label describes, not null
, must have an idIllegalArgumentException
- if the provided component has no idpublic void setFor(String forId)
forId
- the id of the described component, or null
if
there is no valuepublic Optional<String> getFor()
setFor(String)
Copyright © 2023. All rights reserved.