public class SpanLabel

  1. Object
  2. Component
  3. Container
  4. SpanLabel

ImplementsAnimation, Editable, IconHolder, Iterable<Component>, StyleListener, TextHolder

A multi line label component that can be easily localized, this is simply based on a text area combined with a label.

Form hi = new Form("Test SpanLabel", BoxLayout.y());

Image icon = FontImage.createMaterial(FontImage.MATERIAL_INFO, "Label", 3.0f);

SpanLabel d = new SpanLabel("Default SpanLabel that can seamlessly line break when the text is really long.");
d.setIcon(icon);
SpanLabel l = new SpanLabel("NORTH Positioned Icon SpanLabel that can seamlessly line break when the text is really long.");
l.setIcon(icon);
l.setIconPosition(BorderLayout.NORTH);
SpanLabel r = new SpanLabel("SOUTH Positioned Icon SpanLabel that can seamlessly line break when the text is really long.");
r.setIcon(icon);
r.setIconPosition(BorderLayout.SOUTH);
SpanLabel c = new SpanLabel("EAST Positioned Icon SpanLabel that can seamlessly line break when the text is really long.");
c.setIcon(icon);
c.setIconPosition(BorderLayout.EAST);
hi.add(d).add(l).add(r).add(c);
hi.show();

Constructors

public SpanLabel()Default constructor will be useful when adding this to the GUI builder
public SpanLabel(String txt, String textUiid)Constructor accepting default text and uiid for the text
public SpanLabel(String txt)Constructor accepting default text

Methods

public void styleChanged(String propertyName, Style source)Invoked to indicate a change in a propertyName of a Style
protected void initUnselectedStyle(Style unselectedStyle)Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.
protected void initLaf(UIManager uim)This method initializes the Component defaults constants
public int getPreferredW()Helper method to retrieve the preferred width of the component.
public void setPreferredW(int preferredW)Helper method to set the preferred width of the component.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public Component getIconStyleComponent()Gets the component used for styling font icons on this SpanLabel.
public TextArea getTextComponent()Returns the TextArea holding the actual text
public void setUIID(String id)This method sets the Component the Unique identifier.
public String getTextUIID()Returns the uiid of the actual text
public void setTextUIID(String uiid)Sets the UIID for the actual text
public Style getTextAllStyles()Returns the Style proxy object for the text of this span button.
public Style getTextUnselectedStyle()Returns the text elements style object
public void setTextUnselectedStyle(Style t)The text elements style object
public Style getTextSelectedStyle()Returns the text elements style object
public void setTextSelectedStyle(Style t)The text elements style object
public String getIconUIID()Returns the UIID for the icon
public void setIconUIID(String uiid)Sets the uiid for the icon if present
public int getIconValign()Gets the vertical alignment of the icon with respect to the text of the span label.
public void setIconValign(int align)Sets the vertical alignment of the icon with respect to the text of the span label.
public String getText()Returns the text of the label
public void setText(String t)Set the text of the label
public int getTextBlockAlign()Returns the alignment of the whole text block and not the text within it!
public void setTextBlockAlign(int align)Indicates the alignment of the whole text block, this is different from setting the alignment of the text within the block since the UIID might have a border or other design element that won’t be affected by such alignment.
public Image getIcon()Returns the image of the icon
public void setIcon(Image i)Sets the icon for the label
public String getIconPosition()Returns the icon position based on border layout constraints
public void setIconPosition(String t)Sets the icon position based on border layout constraints
public String[] getPropertyNames()A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
public Class[] getPropertyTypes()Matches the property names method (see that method for further details).
public String[] getPropertyTypeNames()This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],I…
public Object getPropertyValue(String name)Returns the current value of the property name, this method is used by the GUI builder
public String setPropertyValue(String name, Object value)Sets a new value to the given property, returns an error message if failed and null if successful.
public boolean isShouldLocalize()Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.
public void setShouldLocalize(boolean shouldLocalize)Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.
public boolean isTextSelectionEnabled()Checks if text selection is enabled on this SpanLabel.
public void setTextSelectionEnabled(boolean enabled)Enables or disables text selection on this span label.
public void setWidth(int width)Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public int getGap()Returns the gap in pixels between the icon/text to the Label boundaries
public void setGap(int gap)Set the gap in pixels between the icon/text to the Label boundaries
public int getTextPosition()Returns The position of the text relative to the icon
public void setTextPosition(int textPosition)Sets the position of the text relative to the icon if exists
public void setFontIcon(Font font, char c)This method is shorthand for com.codename1.ui.Font, char)
public void setMaterialIcon(char c, float size)This method is shorthand for char, float)
public void setFontIcon(Font font, char c, float size)This method is shorthand for com.codename1.ui.Font, char, float)
public char getMaterialIcon()Returns the material icon assigned to this component or 0 if not applicable
public void setMaterialIcon(char c)This method is shorthand for char)
public char getFontIcon()Returns the font icon assigned to this component or 0 if not applicable
public float getMaterialIconSize()Returns the material icon size assigned to this component or 0/-1 if not applicable
public float getFontIconSize()Returns the icon size assigned to this component or 0/-1 if not applicable
public Font getIconFont()Returns the font for the icon font or null if not font set

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paint, paintGlass, layoutContainer, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, getComponentAt, findDropTargetAt, pointerPressed, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

SpanLabel

public SpanLabel()
Default constructor will be useful when adding this to the GUI builder

SpanLabel

public SpanLabel(String txt, String textUiid)
Constructor accepting default text and uiid for the text

Parameters

txt String
the text
textUiid String
the new text UIID

SpanLabel

public SpanLabel(String txt)
Constructor accepting default text

Method details

styleChanged

public void styleChanged(String propertyName, Style source)

Invoked to indicate a change in a propertyName of a Style

NOTE By default this will trigger a call to Container#revalidate() on the parent container, which is expensive. You can disable this behavior by calling CN.setProperty("Component.revalidateOnStyleChange", "false"). The intention is to change this behavior so that the default is to “not” revalidate on style change, so we encourage you to set this to “false” to ensure for future compatibility.

Parameters

propertyName String
the property name that was changed
source Style
The changed Style object

initUnselectedStyle

protected void initUnselectedStyle(Style unselectedStyle)
Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

Parameters

unselectedStyle Style
The unselected style.

initLaf

protected void initLaf(UIManager uim)
This method initializes the Component defaults constants

getPreferredW

public int getPreferredW()
Helper method to retrieve the preferred width of the component.

Returns

preferred width of the component

setPreferredW

public void setPreferredW(int preferredW)
Helper method to set the preferred width of the component.

Parameters

preferredW int
the preferred width of the component

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

getIconStyleComponent

public Component getIconStyleComponent()
Gets the component used for styling font icons on this SpanLabel.

Returns

The component used for styling font icons on this SpanLabel.

getTextComponent

public TextArea getTextComponent()
Returns the TextArea holding the actual text

Returns

the component

setUIID

public void setUIID(String id)
This method sets the Component the Unique identifier. This method should be used before a component has been initialized

Parameters

id String
UIID unique identifier for component type

getTextUIID

public String getTextUIID()
Returns the uiid of the actual text

Returns

the uiid

setTextUIID

public void setTextUIID(String uiid)
Sets the UIID for the actual text

Parameters

uiid String
the uiid

getTextAllStyles

public Style getTextAllStyles()
Returns the Style proxy object for the text of this span button.

Returns

The Style object for the text of this span button.

getTextUnselectedStyle

public Style getTextUnselectedStyle()
Returns the text elements style object

Returns

the style object

setTextUnselectedStyle

public void setTextUnselectedStyle(Style t)
The text elements style object

Parameters

t Style
the style object

getTextSelectedStyle

public Style getTextSelectedStyle()
Returns the text elements style object

Returns

the style object

setTextSelectedStyle

public void setTextSelectedStyle(Style t)
The text elements style object

Parameters

t Style
the style object

getIconUIID

public String getIconUIID()
Returns the UIID for the icon

Returns

the uiid

setIconUIID

public void setIconUIID(String uiid)
Sets the uiid for the icon if present

Parameters

uiid String
the uiid for the icon

getIconValign

public int getIconValign()
Gets the vertical alignment of the icon with respect to the text of the span label.

Returns

The alignment. One of #TOP, #BOTTOM, or #CENTER.

setIconValign

public void setIconValign(int align)
Sets the vertical alignment of the icon with respect to the text of the span label. Default value is #CENTER

Parameters

align int
One of #TOP, #BOTTOM, or #CENTER.

getText

public String getText()
Returns the text of the label

Returns

the text

setText

public void setText(String t)
Set the text of the label

Parameters

t String
text of the label

getTextBlockAlign

public int getTextBlockAlign()
Returns the alignment of the whole text block and not the text within it!

Returns

-1 for unaligned otherwise one of Component.LEFT/RIGHT/CENTER

setTextBlockAlign

public void setTextBlockAlign(int align)
Indicates the alignment of the whole text block, this is different from setting the alignment of the text within the block since the UIID might have a border or other design element that won’t be affected by such alignment. The default is none (-1) which means no alignment takes place and the text block takes the whole width.

Parameters

align int
valid values are Component.LEFT, Component.RIGHT, Component.CENTER. Anything else will stretch the text block

getIcon

public Image getIcon()
Returns the image of the icon

Returns

the icon

setIcon

public void setIcon(Image i)
Sets the icon for the label

Parameters

i Image
the icon

getIconPosition

public String getIconPosition()
Returns the icon position based on border layout constraints

Returns

position either North/South/East/West

setIconPosition

public void setIconPosition(String t)
Sets the icon position based on border layout constraints

Parameters

t String
position either North/South/East/West

getPropertyNames

public String[] getPropertyNames()
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

Returns

the property names allowing mutation

getPropertyTypes

public Class[] getPropertyTypes()
Matches the property names method (see that method for further details).

Returns

the types of the properties

getPropertyTypeNames

public String[] getPropertyTypeNames()
This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

Returns

Array of type names

getPropertyValue

public Object getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder

Parameters

name String
the name of the property

Returns

the value of said property

setPropertyValue

public String setPropertyValue(String name, Object value)
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as “$designMode” might be sent to components to indicate application state.

Parameters

name String
the name of the property
value Object
new value for the property

Returns

error message or null

isShouldLocalize

public boolean isShouldLocalize()
Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.

Returns

the shouldLocalize value

setShouldLocalize

public void setShouldLocalize(boolean shouldLocalize)
Indicates if text should be localized when set to the component, by default all text is localized so this allows disabling automatic localization for a specific component.

Parameters

shouldLocalize boolean
the shouldLocalize to set

isTextSelectionEnabled

public boolean isTextSelectionEnabled()
Checks if text selection is enabled on this SpanLabel. Note that the Form must also have text selection enabled for text selection to work.

Returns

True if text selection is enabled on this element.

setTextSelectionEnabled

public void setTextSelectionEnabled(boolean enabled)
Enables or disables text selection on this span label. Default is off.

Parameters

enabled boolean
True to enable text selection on this label.

setWidth

public void setWidth(int width)

Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.

If a user wishes to affect the component size, setPreferredSize should be used.

Parameters

width int
the width of the component

getGap

public int getGap()
Returns the gap in pixels between the icon/text to the Label boundaries

Returns

the gap in pixels between the icon/text to the Label boundaries

setGap

public void setGap(int gap)
Set the gap in pixels between the icon/text to the Label boundaries

Parameters

gap int
the gap in pixels

getTextPosition

public int getTextPosition()
Returns The position of the text relative to the icon

Returns

The position of the text relative to the icon, one of: LEFT, RIGHT, BOTTOM, TOP

setTextPosition

public void setTextPosition(int textPosition)
Sets the position of the text relative to the icon if exists

Parameters

textPosition int
alignment value (LEFT, RIGHT, BOTTOM or TOP)

setFontIcon

public void setFontIcon(Font font, char c)
This method is shorthand for com.codename1.ui.Font, char)

Parameters

font Font
Not documented.
c char
one of the constants from the font

setMaterialIcon

public void setMaterialIcon(char c, float size)
This method is shorthand for char, float)

Parameters

c char
one of the constants from com.codename1.ui.FontImage
size float
the size of the icon in millimeters

setFontIcon

public void setFontIcon(Font font, char c, float size)
This method is shorthand for com.codename1.ui.Font, char, float)

Parameters

font Font
Not documented.
c char
one of the constants from the font
size float
the size of the icon in millimeters

getMaterialIcon

public char getMaterialIcon()
Returns the material icon assigned to this component or 0 if not applicable

Returns

the material icon

setMaterialIcon

public void setMaterialIcon(char c)
This method is shorthand for char)

Parameters

c char
one of the constants from com.codename1.ui.FontImage

getFontIcon

public char getFontIcon()
Returns the font icon assigned to this component or 0 if not applicable

Returns

the material icon

getMaterialIconSize

public float getMaterialIconSize()
Returns the material icon size assigned to this component or 0/-1 if not applicable

Returns

the material icon size

getFontIconSize

public float getFontIconSize()
Returns the icon size assigned to this component or 0/-1 if not applicable

Returns

the icon size

getIconFont

public Font getIconFont()
Returns the font for the icon font or null if not font set

Returns

the material icon size