Class Label
- All Implemented Interfaces:
Property<String>,Property.ValueChangeListener,Property.ValueChangeNotifier,Property.Viewer,ClientConnector,FAbstractClientConnector,FSizeable,Sizeable,FAbstractComponent,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 ClassesNested classes/interfaces inherited from interface com.vaadin.featurepack.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListenerNested classes/interfaces inherited from interface com.vaadin.featurepack.server.FAbstractClientConnector
FAbstractClientConnector.LegacyMethodEventNested classes/interfaces inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
FAbstractComponent.DataKeyNested classes/interfaces inherited from interface com.vaadin.featurepack.data.Property
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeEvent, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer -
Field Summary
Fields inherited from interface com.vaadin.featurepack.server.Sizeable
SIZE_UNDEFINED -
Constructor Summary
ConstructorsConstructorDescriptionLabel()Creates an empty Label.Creates a new instance of Label with text-contents read from given datasource.Label(Property contentSource, ContentMode contentMode) Creates a new instance of Label with text-contents read from given datasource.Creates a new instance with text content mode and the given text.Label(String text, ContentMode contentMode) Creates a new instance with the given text and content mode. -
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.voidAdds the value change listener.voidbeforeClientResponse(boolean initial) Called before the response is written to client side.protected voidEmits the options change event.Gets the caption of the component.Stream<com.vaadin.flow.component.Component> Gets the content mode of the label.Gets the converter used to convert the property data source value to the label value.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 the viewing data-source property.Gets all user-defined CSS style names of a classic component.getType()Returns the type of the Property.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 HTMLbooleanbooleanTests if the Property is in read-only mode.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.voidRemoves the value change listener.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.voidsetConverter(com.vaadin.flow.data.converter.Converter<String, ?> converter) Sets the converter used to convert the label value to the property data source type.voidsetDescription(String description) Sets the component's description.voidsetDescription(String description, ContentMode contentMode) Sets the component's description using given contentmode.voidsetEnabled(boolean enabled) 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.voidvoidvoidsetPrimaryStyleName(String style) Changes the primary style name of the classic component.voidsetPropertyDataSource(Property newDataSource) Sets the property as data-source for viewing.voidsetPropertyReadOnly(boolean newStatus) Sets the Property's read-only mode to the specified status.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.voidListens the value change events from data source.Methods inherited from class com.vaadin.featurepack.ui.AbstractComponent
addClassName, addClassNames, addInternalStyles, doSetHeight, doSetWidth, fireComponentEvent, fireEvent, focus, getClassName, getClassNames, getInternalStyles, getLocale, getStyle, getTooltip, hasClassName, isOrHasAncestor, isVisible, onEnabledStateChanged, removeClassName, removeClassNames, removeInternalStyles, setClassName, setClassName, setParent, setTooltipText, setVisibleMethods inherited from class com.vaadin.featurepack.server.AbstractClientConnector
getSession, onAttach, onDetachMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, from, get, getElement, getEventBus, getListeners, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setTestId, whenAttachedMethods 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.featurepack.server.FAbstractClientConnector
addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, attach, detach, doConnectorOnAttach, doConnectorOnDetach, fireEvent, fireEvent, getAllChildrenIterable, getFListeners, getFlowComponent, getResource, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeListener, removeListener, setResourceMethods inherited from interface com.vaadin.featurepack.ui.FAbstractComponent
addContextClickListener, addListener, addShortcutListener, getComponentError, getData, getDescription, getFErrorIndicator, getFErrorMessage, getFId, getFParent, getIcon, getIconResource, isImmediate, isResponsive, notifyParentAboutStyleChanges, removeContextClickListener, removeShortcutListener, setComponentError, setData, setIcon, setIcon, setIconResource, setImmediate, setLabelComponent, setLocale, setResponsiveMethods inherited from interface com.vaadin.featurepack.server.FSizeable
getFHeight, getFWidthMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabledMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabelMethods inherited from interface com.vaadin.flow.component.HasStyle
bindClassName, bindClassNamesMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
setTooltipMarkdown
-
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
-
Label
Creates a new instance of Label with text-contents read from given datasource.- Parameters:
contentSource-
-
-
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- Specified by:
beforeClientResponsein interfaceFAbstractClientConnector- Specified by:
beforeClientResponsein interfaceFAbstractComponent- 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.
-
setDescription
Description copied from interface:FAbstractComponentSets the component's description. SeeFAbstractComponent.getDescription()for more information on what the description is.- Specified by:
setDescriptionin interfaceFAbstractComponent- Parameters:
description- the new description string for the component.- See Also:
-
getCaption
Gets the caption of the component.- Specified by:
getCaptionin interfaceFAbstractComponent- Returns:
- the caption of the component or
nullif the caption is not set. - See Also:
-
setCaption
Sets the caption of the component.- Specified by:
setCaptionin interfaceFAbstractComponent- Parameters:
caption- the new caption for the component. If the caption isnull, no caption is shown
-
setLabel
- Specified by:
setLabelin interfacecom.vaadin.flow.component.HasLabel
-
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. -
getValue
Gets the text shown in the label. -
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.
- Specified by:
setCaptionAsHtmlin interfaceFAbstractComponent- 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.
- Specified by:
isCaptionAsHtmlin interfaceFAbstractComponent- 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.
-
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). -
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 interfaceFSizeable- 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.
-
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). -
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 interfaceFSizeable- 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 interfaceFSizeable- Specified by:
setSizeFullin interfaceSizeable- Overrides:
setSizeFullin classAbstractComponent
-
setWidthFull
public void setWidthFull()Description copied from interface:SizeableSets the width to 100%.- Specified by:
setWidthFullin interfaceFSizeable- Specified by:
setWidthFullin interfaceSizeable- Overrides:
setWidthFullin classAbstractComponent
-
setHeightFull
public void setHeightFull()Description copied from interface:SizeableSets the height to 100%.- Specified by:
setHeightFullin interfaceFSizeable- Specified by:
setHeightFullin interfaceSizeable- Overrides:
setHeightFullin classAbstractComponent
-
setSizeUndefined
public void setSizeUndefined()Description copied from interface:SizeableClears any size settings.- Specified by:
setSizeUndefinedin interfaceFSizeable- Specified by:
setSizeUndefinedin interfaceSizeable- Overrides:
setSizeUndefinedin classAbstractComponent
-
setWidthUndefined
public void setWidthUndefined()Description copied from interface:SizeableClears any defined width.- Specified by:
setWidthUndefinedin interfaceFSizeable- Specified by:
setWidthUndefinedin interfaceSizeable- Overrides:
setWidthUndefinedin classAbstractComponent
-
setHeightUndefined
public void setHeightUndefined()Description copied from interface:SizeableClears any defined height.- Specified by:
setHeightUndefinedin interfaceFSizeable- Specified by:
setHeightUndefinedin interfaceSizeable- Overrides:
setHeightUndefinedin classAbstractComponent
-
getStyleName
Description copied from interface:FAbstractComponentGets 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.
- Specified by:
getStyleNamein interfaceFAbstractComponent- Returns:
- the style name or a space-separated list of user-defined style names of the component
- See Also:
-
setStyleName
Description copied from interface:FAbstractComponentSets 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.- Specified by:
setStyleNamein interfaceFAbstractComponent- Parameters:
style- the new style or styles of the component as a space-separated list- See Also:
-
setStyleName
Description copied from interface:FAbstractComponentAdds 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
FAbstractComponent.addStyleName(String)orFAbstractComponent.removeStyleName(String)- Specified by:
setStyleNamein interfaceFAbstractComponent- Parameters:
style- the style name to be added or removedadd-trueto add the given style,falseto remove it- See Also:
-
addStyleName
Description copied from interface:FAbstractComponentAdds 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;}- Specified by:
addStyleNamein interfaceFAbstractComponent- Parameters:
style- the new style to be added to the component- See Also:
-
addStyleNames
Description copied from interface:FAbstractComponentAdds one or more style names to this classic component by using one or multiple parameters.- Specified by:
addStyleNamesin interfaceFAbstractComponent- Parameters:
styles- the style name or style names to be added to the component- See Also:
-
removeStyleName
Description copied from interface:FAbstractComponentRemoves 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.- Specified by:
removeStyleNamein interfaceFAbstractComponent- Parameters:
style- the style name or style names to be removed- See Also:
-
removeStyleNames
Description copied from interface:FAbstractComponentRemoves one or more style names from the classic component. Multiple styles can be specified by using multiple parameters.- Specified by:
removeStyleNamesin interfaceFAbstractComponent- Parameters:
styles- the style name or style names to be removed- See Also:
-
getPrimaryStyleName
Description copied from interface:FAbstractComponentGets the primary style name of the classic component. SeeFAbstractComponent.setPrimaryStyleName(String)for a better description of the primary stylename.- Specified by:
getPrimaryStyleNamein interfaceFAbstractComponent
-
setPrimaryStyleName
Description copied from interface:FAbstractComponentChanges 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.
- Specified by:
setPrimaryStyleNamein interfaceFAbstractComponent- 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()- Specified by:
isEnabledin interfacecom.vaadin.flow.component.HasEnabled
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled
-
setId
- Overrides:
setIdin classcom.vaadin.flow.component.Component
-
getId
- Overrides:
getIdin classcom.vaadin.flow.component.Component
-
getType
Description copied from interface:PropertyReturns the type of the Property. The methodsgetValueandsetValuemust be compatible with this type: one must be able to safely cast the value returned fromgetValueto the given type and pass any variable assignable to this type as an argument tosetValue. -
isPropertyReadOnly
public boolean isPropertyReadOnly()Description copied from interface:PropertyTests if the Property is in read-only mode. In read-only mode calls to the methodsetValuewill throwReadOnlyExceptionand will not modify the value of the Property.- Specified by:
isPropertyReadOnlyin interfaceProperty<String>- Returns:
trueif the Property is in read-only mode,falseif it's not
-
setPropertyReadOnly
public void setPropertyReadOnly(boolean newStatus) Description copied from interface:PropertySets the Property's read-only mode to the specified status. This functionality is optional, but all properties must implement theisReadOnlymode query correctly.- Specified by:
setPropertyReadOnlyin interfaceProperty<String>- Parameters:
newStatus- new read-only status of the Property
-
getPropertyDataSource
Gets the viewing data-source property.- Specified by:
getPropertyDataSourcein interfaceProperty.Viewer- Returns:
- the data source property.
- See Also:
-
setPropertyDataSource
Sets the property as data-source for viewing. Since Vaadin 7.2 a ValueChangeEvent is fired if the new value is different from previous.- Specified by:
setPropertyDataSourcein interfaceProperty.Viewer- Parameters:
newDataSource- the new data source Property- See Also:
-
valueChange
Listens the value change events from data source.- Specified by:
valueChangein interfaceProperty.ValueChangeListener- Parameters:
event- value change event object- See Also:
-
fireValueChange
protected void fireValueChange()Emits the options change event. -
getConverter
Gets the converter used to convert the property data source value to the label value.- Returns:
- The converter or null if none is set.
-
setConverter
Sets the converter used to convert the label value to the property data source type. The converter must have a presentation type of String.- Parameters:
converter- The new converter to use.
-
addValueChangeListener
Adds the value change listener.- Specified by:
addValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- the Listener to be added.- See Also:
-
removeValueChangeListener
Removes the value change listener.- Specified by:
removeValueChangeListenerin interfaceProperty.ValueChangeNotifier- Parameters:
listener- the Listener to be removed.- See Also:
-