Class Label
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.classic.v8.server.AbstractClientConnector
-
- com.vaadin.classic.v8.ui.AbstractComponent
-
- com.vaadin.classic.v8.ui.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,java.io.Serializable
@Tag("div") @CssImport("./label.css") @JsModule("@vaadin/vaadin-lumo-styles/font-icons.js") public class Label extends AbstractComponentLegacy version of Label component for showing non-editable short texts.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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.classic.v8.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.classic.v8.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from interface com.vaadin.classic.v8.server.Sizeable
SIZE_UNDEFINED
-
-
Constructor Summary
Constructors Constructor Description Label()Creates an empty Label.Label(java.lang.String text)Creates a new instance with text content mode and the given text.Label(java.lang.String text, ContentMode contentMode)Creates a new instance with the given text and content mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStyleName(java.lang.String style)Adds one or more style names to the classic component.voidaddStyleNames(java.lang.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.java.lang.StringgetCaption()Gets the caption of the component.java.util.stream.Stream<com.vaadin.flow.component.Component>getChildren()ContentModegetContentMode()Gets the content mode of the label.protected java.util.Collection<java.lang.String>getCustomStyles()Returns the user added custom style names in an unmodifiable collection.floatgetHeight()Gets the height of the object.Sizeable.UnitgetHeightUnits()Gets the height property units.java.util.Optional<java.lang.String>getId()java.lang.StringgetPrimaryStyleName()Gets the primary style name of the classic component.java.lang.StringgetStyleName()Gets all user-defined CSS style names of a classic component.java.lang.StringgetValue()Gets the text shown in the label.floatgetWidth()Gets the width of the object.Sizeable.UnitgetWidthUnits()Gets the width property units.booleanisCaptionAsHtml()Checks whether captions are rendered as HTMLbooleanisEnabled()Tests whether the component is enabled or not.voidremoveStyleName(java.lang.String style)Removes one or more style names from the classic component.voidremoveStyleNames(java.lang.String... styles)Removes one or more style names from the classic component.voidsetCaption(java.lang.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, Sizeable.Unit unit)Sets the height of the object.voidsetHeight(java.lang.String height)Sets the height of the component using String presentation.voidsetHeightFull()Sets the height to 100%.voidsetHeightUndefined()Clears any defined height.voidsetId(java.lang.String id)voidsetPrimaryStyleName(java.lang.String style)Changes the primary style name of the classic component.voidsetSizeFull()Sets the size to 100% x 100%.voidsetSizeUndefined()Clears any size settings.voidsetStyleName(java.lang.String style)Sets one or more user-defined style names of the classic component, replacing any previous user-defined styles.voidsetStyleName(java.lang.String style, boolean add)Adds or removes a style name.voidsetValue(java.lang.String value)Sets the text to be shown in the label.voidsetWidth(float width, Sizeable.Unit unit)Sets the width of the object.voidsetWidth(java.lang.String width)Sets the width of the component using String presentation.voidsetWidthFull()Sets the width to 100%.voidsetWidthUndefined()Clears any defined width.-
Methods inherited from class com.vaadin.classic.v8.ui.AbstractComponent
addInternalStyles, addListener, addShortcutListener, doSetHeight, doSetWidth, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getComponentError, getCustomAttributes, getData, getDescription, getErrorMessage, getIcon, getInternalStyles, getLocale, getState, getState, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, notifyParentAboutStyleChanges, onEnabledStateChanged, removeInternalStyles, setComponentError, setData, setDescription, setDescription, setIcon, setLocale, setParent, setReadOnly, setRequiredIndicatorVisible, setResponsive, setVisible
-
Methods 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, updateDiffstate
-
Methods 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, scrollIntoView, set, setElement
-
-
-
-
Constructor Detail
-
Label
public Label()
Creates an empty Label.
-
Label
public Label(java.lang.String text)
Creates a new instance with text content mode and the given text.- Parameters:
text- the text to set
-
Label
public Label(java.lang.String text, ContentMode contentMode)Creates a new instance with the given text and content mode.- Parameters:
text- the text to setcontentMode- the content mode to use
-
-
Method Detail
-
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
public java.lang.String 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(String)
-
setCaption
public void setCaption(java.lang.String caption)
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
public ContentMode getContentMode()
Gets the content mode of the label.- Returns:
- the content mode of the label
- See Also:
ContentMode
-
setContentMode
public void setContentMode(ContentMode contentMode)
Sets the content mode of the label.- Parameters:
contentMode- the content mode to set- See Also:
ContentMode
-
setValue
public void setValue(java.lang.String value)
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
public java.lang.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
public java.util.stream.Stream<com.vaadin.flow.component.Component> getChildren()
- Overrides:
getChildrenin classcom.vaadin.flow.component.Component
-
setWidth
public void setWidth(java.lang.String width)
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, Sizeable.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 Sizeable.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
public void setHeight(java.lang.String height)
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, Sizeable.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 Sizeable.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
public java.lang.String 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:
AbstractComponent.setStyleName(String),AbstractComponent.addStyleName(String),AbstractComponent.removeStyleName(String)
-
setStyleName
public void setStyleName(java.lang.String style)
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:
AbstractComponent.getStyleName(),AbstractComponent.addStyleName(String),AbstractComponent.removeStyleName(String)
-
setStyleName
public void setStyleName(java.lang.String style, boolean add)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:
AbstractComponent.addStyleName(String),AbstractComponent.removeStyleName(String)
-
addStyleName
public void addStyleName(java.lang.String style)
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:
AbstractComponent.getStyleName(),AbstractComponent.setStyleName(String),AbstractComponent.removeStyleName(String)
-
addStyleNames
public void addStyleNames(java.lang.String... styles)
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:
AbstractComponent.addStyleName(String),AbstractComponent.setStyleName(String),AbstractComponent.removeStyleName(String)
-
removeStyleName
public void removeStyleName(java.lang.String style)
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:
AbstractComponent.getStyleName(),AbstractComponent.setStyleName(String),AbstractComponent.addStyleName(String)
-
removeStyleNames
public void removeStyleNames(java.lang.String... styles)
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:
AbstractComponent.removeStyleName(String),AbstractComponent.setStyleName(String),AbstractComponent.addStyleName(String)
-
getPrimaryStyleName
public java.lang.String 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
public void setPrimaryStyleName(java.lang.String style)
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
protected java.util.Collection<java.lang.String> 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
public void setId(java.lang.String id)
- Overrides:
setIdin classcom.vaadin.flow.component.Component
-
getId
public java.util.Optional<java.lang.String> getId()
- Overrides:
getIdin classcom.vaadin.flow.component.Component
-
-