Class Label
- All Implemented Interfaces:
ClientConnector,Sizeable,com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.shared.HasTooltip,Serializable
The label content can be set to the modes specified by ContentMode.
If content mode is set to HTML, any HTML content is allowed.
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.classic.v8.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListener -
Field Summary
Fields inherited from interface com.vaadin.classic.v8.server.Sizeable
SIZE_UNDEFINED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStyleName(String style) Adds one or more style names to the classic component.voidaddStyleNames(String... styles) Adds one or more style names to this classic component by using one or multiple parameters.voidbeforeClientResponse(boolean initial) Called before the response is written to client side.Gets the caption of the component.Stream<com.vaadin.flow.component.Component>Gets the content mode of the label.protected Collection<String>Returns the user added custom style names in an unmodifiable collection.floatGets the height of the object.com.vaadin.flow.component.UnitGets the height property units.getId()Gets the primary style name of the classic component.Gets all user-defined CSS style names of a classic component.getValue()Gets the text shown in the label.floatgetWidth()Gets the width of the object.com.vaadin.flow.component.UnitGets the width property units.booleanChecks whether captions are rendered as HTMLbooleanTests whether the component is enabled or not.voidremoveStyleName(String style) Removes one or more style names from the classic component.voidremoveStyleNames(String... styles) Removes one or more style names from the classic component.voidsetCaption(String caption) Sets the caption of the component.voidsetCaptionAsHtml(boolean captionAsHtml) Sets whether the caption is rendered as HTML.voidsetContentMode(ContentMode contentMode) Sets the content mode of the label.voidsetEnabled(boolean enabled) Enables or disables the component.voidsetHeight(float height, com.vaadin.flow.component.Unit unit) Sets the height of the object.voidSets the height of the component using String presentation.voidSets the height to 100%.voidClears any defined height.voidvoidsetPrimaryStyleName(String style) Changes the primary style name of the classic component.voidSets the size to 100% x 100%.voidClears any size settings.voidsetStyleName(String style) Sets one or more user-defined style names of the classic component, replacing any previous user-defined styles.voidsetStyleName(String style, boolean add) Adds or removes a style name.voidSets the text to be shown in the label.voidsetWidth(float width, com.vaadin.flow.component.Unit unit) Sets the width of the object.voidSets the width of the component using String presentation.voidSets the width to 100%.voidClears any defined width.Methods inherited from class com.vaadin.classic.v8.ui.AbstractComponent
addClassName, addClassNames, addInternalStyles, addListener, addShortcutListener, doSetHeight, doSetWidth, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getClassName, getClassNames, getComponentError, getCustomAttributes, getData, getDescription, getErrorMessage, getIcon, getInternalStyles, getLabel, getLocale, getState, getState, getStyle, getTooltip, hasClassName, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, notifyParentAboutStyleChanges, onEnabledStateChanged, removeClassName, removeClassNames, removeInternalStyles, setClassName, setClassName, setComponentError, setData, setDescription, setDescription, setIcon, setLabel, setLocale, setParent, setReadOnly, setRequiredIndicatorVisible, setResponsive, setTooltipText, setVisibleMethods inherited from class com.vaadin.classic.v8.server.AbstractClientConnector
addExtension, addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, addMethodInvocationToQueue, attach, createState, detach, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getResource, getSession, handleConnectorRequest, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, onAttach, onDetach, registerRpc, registerRpc, removeExtension, setErrorHandler, setResource, updateDiffstateMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getListeners, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, removeFromParent, scrollIntoView, scrollIntoView, set, setElementMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Constructor Details
-
Label
public Label()Creates an empty Label. -
Label
Creates a new instance with text content mode and the given text.- Parameters:
text- the text to set
-
-
Method Details
-
beforeClientResponse
public void beforeClientResponse(boolean initial) Description copied from interface:ClientConnectorCalled before the response is written to client side. Gives the legacy connector an opportunity to set computed/dynamic state values.This is implemented for the legacy components to keep consistent behavior and e.g. legaze size calculations working.
NOTE: the parameter
initialisfalsewhen the component is attached again to a newUIwhenPreserveOnRefreshis used.- Specified by:
beforeClientResponsein interfaceClientConnector- Overrides:
beforeClientResponsein classAbstractComponent- Parameters:
initial-trueif the client-side connector will be created and initialized after this method has been invoked.falseif there is already an initialized client-side connector.
-
getCaption
Gets the caption of the component.- Overrides:
getCaptionin classAbstractComponent- Returns:
- the caption of the component or
nullif the caption is not set. - See Also:
-
setCaption
Sets the caption of the component.- Overrides:
setCaptionin classAbstractComponent- Parameters:
caption- the new caption for the component. If the caption isnull, no caption is shown
-
getContentMode
Gets the content mode of the label.- Returns:
- the content mode of the label
- See Also:
-
setValue
Sets the text to be shown in the label.- Parameters:
value- the text to show in the label, null is converted to an empty string
-
getValue
Gets the text shown in the label.- Returns:
- the text shown in the label, not null
-
setCaptionAsHtml
public void setCaptionAsHtml(boolean captionAsHtml) Sets whether the caption is rendered as HTML.If set to true, the captions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.
Note: Unlike the Label component in Vaadin 7/8, the script tag is removed when the caption is rendered as html The default is false, i.e. to render that caption as plain text.
- Overrides:
setCaptionAsHtmlin classAbstractComponent- Parameters:
captionAsHtml- true if the captions are rendered as HTML, false if rendered as plain text
-
isCaptionAsHtml
public boolean isCaptionAsHtml()Checks whether captions are rendered as HTMLThe default is false, i.e. to render that caption as plain text.
- Overrides:
isCaptionAsHtmlin classAbstractComponent- Returns:
- true if the captions are rendered as HTML, false if rendered as plain text
-
getChildren
- Overrides:
getChildrenin classcom.vaadin.flow.component.Component
-
setWidth
Description copied from interface:SizeableSets the width of the component using String presentation.String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.
The empty string ("") or null will unset the width and set the units to pixels.
See CSS specification for more details.
- Specified by:
setWidthin interfaceSizeable- Overrides:
setWidthin classAbstractComponent- Parameters:
width- in CSS style string representation, null or empty string to reset
-
setWidth
public void setWidth(float width, com.vaadin.flow.component.Unit unit) Description copied from interface:SizeableSets the width of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setWidthin interfaceSizeable- Overrides:
setWidthin classAbstractComponent- Parameters:
width- the width of the object.unit- the unit used for the width.
-
getWidth
public float getWidth()Description copied from interface:SizeableGets the width of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
getWidthin interfaceSizeable- Overrides:
getWidthin classAbstractComponent- Returns:
- width of the object in units specified by widthUnits property.
-
getWidthUnits
public com.vaadin.flow.component.Unit getWidthUnits()Description copied from interface:SizeableGets the width property units.- Specified by:
getWidthUnitsin interfaceSizeable- Overrides:
getWidthUnitsin classAbstractComponent- Returns:
- units used in width property.
-
setHeight
Description copied from interface:SizeableSets the height of the component using String presentation.String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.
The empty string ("") or null will unset the height and set the units to pixels.
See CSS specification for more details.
- Specified by:
setHeightin interfaceSizeable- Overrides:
setHeightin classAbstractComponent- Parameters:
height- in CSS style string representation
-
setHeight
public void setHeight(float height, com.vaadin.flow.component.Unit unit) Description copied from interface:SizeableSets the height of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setHeightin interfaceSizeable- Overrides:
setHeightin classAbstractComponent- Parameters:
height- the height of the object.unit- the unit used for the width.
-
getHeight
public float getHeight()Description copied from interface:SizeableGets the height of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
getHeightin interfaceSizeable- Overrides:
getHeightin classAbstractComponent- Returns:
- height of the object in units specified by heightUnits property.
-
getHeightUnits
public com.vaadin.flow.component.Unit getHeightUnits()Description copied from interface:SizeableGets the height property units.- Specified by:
getHeightUnitsin interfaceSizeable- Overrides:
getHeightUnitsin classAbstractComponent- Returns:
- units used in height property.
-
setSizeFull
public void setSizeFull()Description copied from interface:SizeableSets the size to 100% x 100%.- Specified by:
setSizeFullin interfaceSizeable- Overrides:
setSizeFullin classAbstractComponent
-
setWidthFull
public void setWidthFull()Description copied from interface:SizeableSets the width to 100%.- Specified by:
setWidthFullin interfaceSizeable- Overrides:
setWidthFullin classAbstractComponent
-
setHeightFull
public void setHeightFull()Description copied from interface:SizeableSets the height to 100%.- Specified by:
setHeightFullin interfaceSizeable- Overrides:
setHeightFullin classAbstractComponent
-
setSizeUndefined
public void setSizeUndefined()Description copied from interface:SizeableClears any size settings.- Specified by:
setSizeUndefinedin interfaceSizeable- Overrides:
setSizeUndefinedin classAbstractComponent
-
setWidthUndefined
public void setWidthUndefined()Description copied from interface:SizeableClears any defined width.- Specified by:
setWidthUndefinedin interfaceSizeable- Overrides:
setWidthUndefinedin classAbstractComponent
-
setHeightUndefined
public void setHeightUndefined()Description copied from interface:SizeableClears any defined height.- Specified by:
setHeightUndefinedin interfaceSizeable- Overrides:
setHeightUndefinedin classAbstractComponent
-
getStyleName
Description copied from class:AbstractComponentGets all user-defined CSS style names of a classic component. If the component has multiple style names defined, the return string is a space-separated list of style names. Built-in style names defined in Vaadin or GWT are not returned.The style names are returned only in the basic form in which they were added; each user-defined style name shows as two CSS style class names in the rendered HTML: one as it was given and one prefixed with the component-specific style name. Only the former is returned.
- Overrides:
getStyleNamein classAbstractComponent- Returns:
- the style name or a space-separated list of user-defined style names of the component
- See Also:
-
setStyleName
Description copied from class:AbstractComponentSets one or more user-defined style names of the classic component, replacing any previous user-defined styles. Multiple styles can be specified as a space-separated list of style names. The style names must be valid CSS class names and should not conflict with any built-in style names in Vaadin or GWT.Label label = new Label("This text has a lot of style"); label.setStyleName("myonestyle myotherstyle");Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Labelcomponent and give it "mystyle" style, the component will have both "mystyle" and "v-label-mystyle" styles. You could then style the component either with:.mystyle {background: blue;}or
.v-label-mystyle {background: blue;}It is normally a good practice to use
addStyleName()rather than this setter, as different software abstraction layers can then add their own styles without accidentally removing those defined in other layers.- Overrides:
setStyleNamein classAbstractComponent- Parameters:
style- the new style or styles of the component as a space-separated list- See Also:
-
setStyleName
Description copied from class:AbstractComponentAdds or removes a style name. Multiple styles can be specified as a space-separated list of style names.If the
addparameter is true, the style name is added to the component. If theaddparameter is false, the style name is removed from the component.Functionally this is equivalent to using
AbstractComponent.addStyleName(String)orAbstractComponent.removeStyleName(String)- Overrides:
setStyleNamein classAbstractComponent- Parameters:
style- the style name to be added or removedadd-trueto add the given style,falseto remove it- See Also:
-
addStyleName
Description copied from class:AbstractComponentAdds one or more style names to the classic component. Multiple styles can be specified as a space-separated list of style names. The style name will be rendered as a HTML class name, which can be used in a CSS definition.Label label = new Label("This text has style"); label.addStyleName("mystyle");Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Labelcomponent and give it "mystyle" style, the component will have both "mystyle" and "v-label-mystyle" styles. You could then style the component either with:.mystyle {font-style: italic;}or
.v-label-mystyle {font-style: italic;}- Overrides:
addStyleNamein classAbstractComponent- Parameters:
style- the new style to be added to the component- See Also:
-
addStyleNames
Description copied from class:AbstractComponentAdds one or more style names to this classic component by using one or multiple parameters.- Overrides:
addStyleNamesin classAbstractComponent- Parameters:
styles- the style name or style names to be added to the component- See Also:
-
removeStyleName
Description copied from class:AbstractComponentRemoves one or more style names from the classic component. Multiple styles can be specified as a space-separated list of style names.The parameter must be a valid CSS style name. Only user-defined style names added with
addStyleName()orsetStyleName()can be removed; built-in style names defined in Vaadin or GWT can not be removed.- Overrides:
removeStyleNamein classAbstractComponent- Parameters:
style- the style name or style names to be removed- See Also:
-
removeStyleNames
Description copied from class:AbstractComponentRemoves one or more style names from the classic component. Multiple styles can be specified by using multiple parameters.- Overrides:
removeStyleNamesin classAbstractComponent- Parameters:
styles- the style name or style names to be removed- See Also:
-
getPrimaryStyleName
Description copied from class:AbstractComponentGets the primary style name of the classic component. SeeAbstractComponent.setPrimaryStyleName(String)for a better description of the primary stylename.- Overrides:
getPrimaryStyleNamein classAbstractComponent
-
setPrimaryStyleName
Description copied from class:AbstractComponentChanges the primary style name of the classic component.The primary style name identifies the component when applying the CSS theme to the Component. By changing the style name all CSS rules targeted for that style name will no longer apply, and might result in the component not working as intended.
- Overrides:
setPrimaryStyleNamein classAbstractComponent- Parameters:
style- The new primary style name
-
getCustomStyles
Description copied from class:AbstractComponentReturns the user added custom style names in an unmodifiable collection.- Overrides:
getCustomStylesin classAbstractComponent- Returns:
- the user added custom style names
-
isEnabled
public boolean isEnabled()Description copied from class:AbstractComponentTests whether the component is enabled or not. A user can not interact with disabled components. Disabled components are rendered in a style that indicates the status, usually in gray color. Children of a disabled component are also disabled. Components are enabled by default.As a security feature, all updates for disabled components are blocked on the server-side.
Note that this method only returns the status of the component and does not take parents into account. Even though this method returns true the component can be disabled to the user if a parent is disabled.
- Specified by:
isEnabledin interfacecom.vaadin.flow.component.HasEnabled- Overrides:
isEnabledin classAbstractComponent- Returns:
trueif the component and its parent are enabled,falseotherwise.
-
setEnabled
public void setEnabled(boolean enabled) Description copied from class:AbstractComponentEnables or disables the component. The user can not interact with disabled components, which are shown with a style that indicates the status, usually shaded in light gray color. Components are enabled by default.Button enabled = new Button("Enabled"); enabled.setEnabled(true); // The default layout.addComponent(enabled); Button disabled = new Button("Disabled"); disabled.setEnabled(false); layout.addComponent(disabled);- Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled- Overrides:
setEnabledin classAbstractComponent- Parameters:
enabled- a boolean value specifying if the component should be enabled or not
-
setId
- Overrides:
setIdin classcom.vaadin.flow.component.Component
-
getId
- Overrides:
getIdin classcom.vaadin.flow.component.Component
-