Class SJLabel
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, ComponentMixin, ContainerMixin, JComponentMixin, Serializable
JLabel. Extends Vaadin
NativeLabel (<label> element) implements
JComponentMixin. Reaches the migrator either through
:emulators.JLabel as peer, or as a richer-than-stock Vaadin
component in its own right.
Why NativeLabel, not Span
JLabel's labelFor relationship is the
<label for="…"> accessibility wiring — Vaadin's
NativeLabel.setFor(Component) hits that contract directly,
whereas Span doesn't carry the for attribute. Visual
shape (one inline element holding text + optional icon) is identical
either way, so the labelFor wire is the deciding factor.
DOM management — manual children, not setText
Vaadin HasText.setText(String) writes to the
element's text content via Element.setText(String),
which removes all children (text nodes and elements)
before inserting a single text node. That's incompatible with hosting
an icon child element alongside the text. This surrogate sidesteps
the issue by:
- holding an inner
Span(textSpan) as a stable text-bearing child —setTextwrites through the inner Span, leaving any icon sibling untouched; - holding the icon (when present) as a
Componentchild inserted at index 0 of the host<label>, so the visual order is icon-then-text matching JDK'shorizontalTextPosition == TRAILINGdefault.
R_vaadin_first stance — what's wired, what drops
UI-functional / wired:
text— written totextSpan, read back from same.icon— encoded viaIcons.toVaadinIconComponent(Object, Icon)(icon-rendering Path 1 / D_icon_rendering); rendered as a VaadinImagechild of the label. Non-ImageIconIconimpls drop with a WARN (Path 2 / Path 3 deferred).labelFor— delegates toNativeLabel.setFor(Component)so the rendered<label>carries the rightforattribute.
Layout — display: inline-flex drives alignment + text-position + gap
The host <label> runs as display: inline-flex; the
four alignment / text-position setters and iconTextGap all
map onto flex CSS:
horizontalTextPositiondrivesflex-directionon the row axis:TRAILING/RIGHT→row(icon before text, JDK default),LEADING/LEFT→row-reverse(text before icon).verticalTextPositionpromotes the layout to a column when non-CENTER:TOP→column-reverse(text above icon),BOTTOM→column(text below icon). WhenverticalTextPosition == CENTERthe row direction wins — matches JDK's "icon and text side-by-side" default.horizontalAlignmentdrivesjustify-content:LEFT/LEADING→flex-start,CENTER→center,RIGHT/TRAILING→flex-end. Visible only when the label has explicit width; a shrink-wrap label (no size set) lays out flush either way.verticalAlignmentdrivesalign-items:TOP→flex-start,CENTER→center,BOTTOM→flex-end. Same shrink-wrap caveat.iconTextGap→ CSSgap.
R_match_swing_errors IAE preserved before any CSS write (bad SwingConstants axis
still throws). Getters lossy-parse CSS back per R_vaadin_first — same shape as
setBorder / getBorder (SD_border_css_lossy): LEFT and LEADING both
round-trip as LEADING (canonical), RIGHT and TRAILING as TRAILING;
verticalTextPosition non-CENTER masks
horizontalTextPosition (column/column-reverse can't encode
the row-axis value, so getHorizontalTextPosition reports the
JDK default TRAILING in that state).
displayedMnemonic / displayedMnemonicIndex stay
Bucket B noops — JLabel's mnemonic visually underlines a character,
which has no Vaadin counterpart, and the accelerator-binding aspect
needs the labelFor target's focus integration that Vaadin's
<label for> doesn't surface client-side. R_match_swing_errors IAE on
out-of-range index still fires.
Inherited from JComponentMixin: client properties,
borders (CSS round-trip per SD_border_css_lossy), opaque flag, tooltip, key/focus
listeners, plus the standard ComponentMixin surface.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
com.vaadin.flow.component.HasText.WhiteSpaceNested classes/interfaces inherited from interface JComponentMixin
JComponentMixin.ActionStandin -
Field Summary
Fields inherited from interface JComponentMixin
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintintintintcom.vaadin.flow.component.ComponentgetIcon()Returns the VaadinComponentcurrently installed as the icon child, ornullwhen no icon is set.intcom.vaadin.flow.component.ComponentgetText()Reads back from the innertextSpan(plain-text mode) or fromhtmlTextwhen an HTML payload was set.Deliberate no-op — L&F key.intintvoidsetDisplayedMnemonic(char aChar) voidsetDisplayedMnemonic(int key) voidsetDisplayedMnemonicIndex(int index) voidsetHorizontalAlignment(int alignment) voidsetHorizontalTextPosition(int textPosition) voidEncode the icon viaIcons.toVaadinIconComponent(Object, Icon)(Path 1) and install as a child of the host<label>.voidsetIconTextGap(int iconTextGap) voidsetLabelFor(com.vaadin.flow.component.Component target) Routes toNativeLabel.setFor(String)after ensuring the target has a server-side id (Vaadin requires one for thefor=attribute write; JDKJLabel.setLabelFordoes not).voidWrites to the innertextSpan(preserving any icon sibling) and fires the"text"PCE.voidsetVerticalAlignment(int alignment) voidsetVerticalTextPosition(int textPosition) voidupdateUI()L&F dispatch isn't modeled; matchesJComponentMixin's no-op stance.Methods inherited from class com.vaadin.flow.component.html.NativeLabel
getFor, setFor, setForMethods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface ComponentMixin
_installSwingClass, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, dispatchEvent, doLayout, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getComponentListeners, getCursor, getFocusListeners, getFont, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getKeyListeners, getLocation, getMaximumSize, getMinimumSize, getMouseListeners, getName, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolTipText, getX, getY, grabFocus, hasFocus, invalidate, isDisplayable, isFocusable, isFocusOwner, isShowing, paint, paintAll, print, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, revalidate, setBackground, setBounds, setBounds, setCursor, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateMethods inherited from interface ContainerMixin
addContainerListener, getContainerListeners, getLayout, paintComponents, printComponents, removeContainerListener, setLayoutMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, add, addComponentAsFirst, addComponentAtIndex, bindChildren, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replaceMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
bindText, getWhiteSpace, setWhiteSpaceMethods inherited from interface JComponentMixin
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, requestDefaultFocus, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction
-
Constructor Details
-
SJLabel
public SJLabel() -
SJLabel
-
SJLabel
JDK convention: an icon-only label centers its content. -
SJLabel
-
-
Method Details
-
getText
Reads back from the innertextSpan(plain-text mode) or fromhtmlTextwhen an HTML payload was set. Returns""(notnull) on a freshly-constructed label whose text was never set — VaadinSpan.getText()returns""for an empty element. Migrated code that null-checks JLabel text needs to""-check on this layer; the emulator preserves null at its own field shadow.- Specified by:
getTextin interfacecom.vaadin.flow.component.HasText
-
setText
Writes to the innertextSpan(preserving any icon sibling) and fires the"text"PCE. Mirrors Swing JLabel's two paths: when the string starts with<html>(Swing'sBasicHTML.isHTMLStringrule, case-insensitive), the inner span receives parsed DOM viainnerHTML; outer<html>/<body>wrappers are stripped so the rendered subtree is well-formed. Plain text usesHasText.setText(String). Transitioning HTML → plain clears DOM children before reseeding the text node.nullwrites land as"".- Specified by:
setTextin interfacecom.vaadin.flow.component.HasText
-
getIcon
public com.vaadin.flow.component.Component getIcon()Returns the VaadinComponentcurrently installed as the icon child, ornullwhen no icon is set. Vaadin-typed per R_vaadin_first — pure-surrogate users access the icon via this Vaadin handle; migrated code that wants the JDKIconref reads it from the emulator layer. -
setIcon
Encode the icon viaIcons.toVaadinIconComponent(Object, Icon)(Path 1) and install as a child of the host<label>. Replaces any previous icon child;nullclears the slot. Fires"icon"PCE with Vaadin-typed values per R_vaadin_first (the JDKIconref isn't shadow-stored). -
getLabelFor
public com.vaadin.flow.component.Component getLabelFor() -
setLabelFor
public void setLabelFor(com.vaadin.flow.component.Component target) Routes toNativeLabel.setFor(String)after ensuring the target has a server-side id (Vaadin requires one for thefor=attribute write; JDKJLabel.setLabelFordoes not). When the target has no id, mint a stable"emul-labelfor-N"suffix and set it before delegating.nullclears the slot. Fires"labelFor"PCE. -
getHorizontalAlignment
public int getHorizontalAlignment() -
setHorizontalAlignment
public void setHorizontalAlignment(int alignment) -
getVerticalAlignment
public int getVerticalAlignment() -
setVerticalAlignment
public void setVerticalAlignment(int alignment) -
getHorizontalTextPosition
public int getHorizontalTextPosition() -
setHorizontalTextPosition
public void setHorizontalTextPosition(int textPosition) -
getVerticalTextPosition
public int getVerticalTextPosition() -
setVerticalTextPosition
public void setVerticalTextPosition(int textPosition) -
getIconTextGap
public int getIconTextGap() -
setIconTextGap
public void setIconTextGap(int iconTextGap) -
getDisplayedMnemonic
public int getDisplayedMnemonic() -
setDisplayedMnemonic
public void setDisplayedMnemonic(int key) -
setDisplayedMnemonic
public void setDisplayedMnemonic(char aChar) -
getDisplayedMnemonicIndex
public int getDisplayedMnemonicIndex() -
setDisplayedMnemonicIndex
public void setDisplayedMnemonicIndex(int index) -
getUIClassID
Description copied from interface:JComponentMixinDeliberate no-op — L&F key.- Specified by:
getUIClassIDin interfaceJComponentMixin
-
updateUI
public void updateUI()L&F dispatch isn't modeled; matchesJComponentMixin's no-op stance.- Specified by:
updateUIin interfaceJComponentMixin
-