com.vaadin.flow.component.html.
Class Label
All Implemented Interfaces:
AttachNotifier
, DetachNotifier
, HasComponents
, HasElement
, HasEnabled
, HasSize
, HasStyle
, HasText
, Serializable
Component for a <label>
element, which represents a
caption for an item in a user interface.
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. If the text should be
interpreted as HTML, use a Html
(but remember to guard against
cross-site scripting attacks).
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetFor()
Deprecated, for removal: This API element is subject to removal in a future version.
Gets the id of the component that this label describes.
protected void
onAttach
(AttachEvent attachEvent) Deprecated, for removal: This API element is subject to removal in a future version.
Called when the component is attached to a UI.
void
Deprecated, for removal: This API element is subject to removal in a future version.
Sets the component that this label describes.
void
Deprecated, for removal: This API element is subject to removal in a future version.
Sets the id of the component that this label describes.
Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitle
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
Methods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
Constructor Details
-
Label
public Label()Deprecated, for removal: This API element is subject to removal in a future version.Creates a new empty label.
-
Label
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new label with the given text content.
Parameters:
text
- the text content
-
-
Method Details
-
setFor
Deprecated, for removal: This API element is subject to removal in a future version.Sets the component that this label describes. The component (or its id) should be defined in case the described component is not an ancestor of the label.
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.
Parameters:
forComponent
- the component that this label describes, notnull
, must have an idThrows:
IllegalArgumentException
- if the provided component has no id -
setFor
Deprecated, for removal: This API element is subject to removal in a future version.Sets the id of the component that this label describes. The id should be defined in case the described component is not an ancestor of the label.
Parameters:
forId
- the id of the described component, ornull
if there is no value -
getFor
Deprecated, for removal: This API element is subject to removal in a future version.Gets the id of the component that this label describes.
Returns:
an optional id of the described component, or an empty optional if the attribute has not been set
See Also:
-
onAttach
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from class:
Component
Called when the component is attached to a UI.
This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method.
-
NativeLabel
instead, if you need the HTML<label>
element, which is normally not needed within a Vaadin Flow application's high-level components. To use a Label that works in the older style of Vaadin 8 or Java Swing, and can be used both to label a component and to display loose text, an alternative is the Label available in Classic Components. ThisLabel
component /<label>
element is not meant for loose text in the page - it should only be coupled with another component by using thesetFor(Component)
or by adding them to it with theHasComponents.add(Component...)
method, for example if you useInput
.