public class Label

  1. Object
  2. Component
  3. Label

ImplementsAnimation, Editable, IconHolder, StyleListener, TextHolder

Known subtypesScaleImageLabel, Button, Slider, DefaultListCellRenderer

Allows displaying a single line of text and icon (both optional) with different alignment options. This class is a base class for several components allowing them to declare alignment/icon appearance universally.

Label text can be positioned in one of 4 locations as such:

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

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

Label left = new Label("Left", icon);
left.setTextPosition(Component.LEFT);
Label right = new Label("Right", icon);
right.setTextPosition(Component.RIGHT);
Label bottom = new Label("Bottom", icon);
bottom.setTextPosition(Component.BOTTOM);
Label top = new Label("Top", icon);
top.setTextPosition(Component.TOP);
hi.add(left).add(right).add(bottom).add(top);
hi.show();

Constructors

public Label(String text)Constructs a new label with the specified string of text, left justified.
public Label(String text, String uiid)Constructs a new label with the specified string of text and uiid
public Label()Construct an empty label
public Label(Image icon)Constructs a new label with the specified icon
public Label(Image icon, String uiid)Constructs a new label with the specified icon and UIID
public Label(String text, Image icon, String uiid)Constructs a new label with the specified icon text and UIID
public Label(String text, Image icon)Constructs a new label with the specified icon and text

Methods

public static int getDefaultGap()Returns the default gap in pixels between the icon/text to the Label boundaries
public static void setDefaultGap(int gap)Set the default gap in pixels between the icon/text to the Label boundaries
public static boolean isDefaultTickerEnabled()Allows disabling/enabling tickers globally
public static void setDefaultTickerEnabled(boolean aDefaultTickerEnabled)Allows disabling/enabling tickers globally
protected void laidOut()This is a callback method to inform the Component when it’s been laidout on the parent Container This is overriden for auto size mode
public String getBadgeText()Gets the text to be used in a badge on this label.
public void setBadgeText(String badgeText)Sets the badge text to be used on this label.
public void setBadgeUIID(String badgeUIID)Sets the style that should be used for rendering badges.
public Component getBadgeStyleComponent()Gets a component that can be used for the style of the badge.
public Component getIconStyleComponent()Gets the component that should be used for styling material the material icon.
public void setFontIcon(Font font, char c)This method is shorthand for Font, char, float)
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 void setFontIcon(char c)Sets an icon font using either the same icon font that was used to set the icon font last, or using the font from the icon UIID.
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
public int getBaselineResizeBehavior()Returns a constant indicating how the baseline varies with the size of the component.
public int getBaseline(int width, int height)The baseline for the component text according to which it should be aligned with other components for best visual look.
public void setUIID(String id)This method sets the Component the Unique identifier.
public void refreshTheme(boolean merge)Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
protected void initLaf(UIManager uim)This method initializes the Component defaults constants
public String getText()Returns the label text
public void setText(String text)Sets the Label text
public Image getIcon()Returns the labels icon
public void setIcon(Image icon)Sets the Label icon, if the icon is unmodified a repaint would not be triggered
public int getVerticalAlignment()Returns the vertical alignment of the Label, this will only work when the icon is in the side of the text and not above or below it.
public void setVerticalAlignment(int valign)Sets the vertical alignment of the Label to one of: CENTER, TOP, BOTTOM, BASELINE The valign property is only relevant relatively to the icon and not the entire label, this will only work when there is an icon
public int getAlignment()Deprecated Returns the alignment of the Label
public void setAlignment(int align)Deprecated Sets the Alignment of the Label to one of: CENTER, LEFT, RIGHT
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 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
protected String paramString()Returns a string representing the state of this component.
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.
public float getMaxAutoSize()Allows us to limit the maximum size for the autosize mode
public void setMaxAutoSize(float maxSize)Allows us to limit the maximum size for the autosize mode
public float getMinAutoSize()Allows us to limit the minimum size for the autosize mode
public void setMinAutoSize(float minSize)Allows us to limit the minimum size for the autosize mode
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public int getShiftText()Simple getter to return how many pixels to shift the text inside the Label
public void setShiftText(int shiftText)This method shifts the text from it’s position in pixels.
public boolean shouldTickerStart()Returns true if a ticker should be started since there is no room to show the text in the label.
public void startTicker()This method will start the text ticker
public void startTicker(long delay, boolean rightToLeft)This method will start the text ticker
public void stopTicker()Stops the text ticker
public boolean isTickerRunning()Returns true if the ticker is running
public boolean isTickerEnabled()This method return true if the ticker is enabled on this Label
public void setTickerEnabled(boolean tickerEnabled)Sets the Label to allow ticking of the text.
public boolean isEndsWith3Points()If the Label text is too long fit the text to the widget and adds “...” points at the end.
public void setEndsWith3Points(boolean endsWith3Points)If the Label text is too long fit the text to the widget and adds “...” points at the end.
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
public Object getMask()Returns the mask matching the given image
public void setMask(Object mask)A mask image can be applied to the label (see the image mask method for details) which allows for things like rounded image appearance etc.
public String getMaskName()Determines the name of the mask from the image constants thus allowing the mask to be applied from the theme
public void setMaskName(String maskName)Determines the name of the mask from the image constants thus allowing the mask to be applied from the theme
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 Image getMaskedIcon()If a mask is applied returns the icon with a mask, otherwise returns the icon
public String[] getBindablePropertyNames()Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound
public Class[] getBindablePropertyTypes()Returns the types of the properties that are bindable within this component
public void bindProperty(String prop, BindTarget target)Deprecated Binds the given property name to the given bind target
public void unbindProperty(String prop, BindTarget target)Deprecated Removes a bind target from the given property name
public Object getBoundPropertyValue(String prop)Allows the binding code to extract the value of the property
public void setBoundPropertyValue(String prop, Object value)Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!
public boolean isShouldLocalize()Indicates if text should be localized when set to the label, by default all text is localized so this allows disabling automatic localization for a specific label.
public void setShouldLocalize(boolean shouldLocalize)Indicates if text should be localized when set to the label, by default all text is localized so this allows disabling automatic localization for a specific label.
public int getShiftMillimeters()Deprecated Returns the number of millimeters that should be shifted in tickering rounded to nearest int.
public void setShiftMillimeters(int shiftMillimeters)Sets the millimeters that should be shifted in tickering
public void setShiftMillimeters(float shiftMillimeters)Sets the millimeters that should be shifted in tickering as a float.
public float getShiftMillimetersF()Returns the number of millimeters that should be shifted in tickering as a float.
public boolean isShowEvenIfBlank()By default labels and subclasses become 0 sized when they are blank even ignoring their padding setting this to true makes the padding take effect even in a blank field.
public final void setShowEvenIfBlank(boolean showEvenIfBlank)By default labels and subclasses become 0 sized when they are blank even ignoring their padding setting this to true makes the padding take effect even in a blank field.
public int getStringWidth(Font fnt)This method is equivalent to label.getStyle().getFont().stringWidth(label.getText()) but its faster
public boolean isLegacyRenderer()Fallback to the old default look and feel renderer for cases where compatibility is essential
public void setLegacyRenderer(boolean legacyRenderer)Fallback to the old default look and feel renderer for cases where compatibility is essential
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.
public boolean isAutoSizeMode()Autosize mode automatically shrinks/grows the font of the label to fit in the available width, it carries a noticeable performance penalty and we recommend you avoid using it unless absolutely necessary
public void setAutoSizeMode(boolean autoSizeMode)Autosize mode automatically shrinks/grows the font of the label to fit in the available width, it carries a noticeable performance penalty and we recommend you avoid using it unless absolutely necessary
public boolean isTextSelectionEnabled()Returns true if text selection is enabled on this label.
public void setTextSelectionEnabled(boolean enabled)Enables text selection on this label.
public TextSelection.TextSelectionSupport getTextSelectionSupport()Returns text selection support object for this component.
public String getIconUIID()Gets the UIID used for styling material icons on this component.
public void setIconUIID(String uiid)Sets a UIID to be used for the material icon style.

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, 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, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, keyReleased, 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, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerDragged, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerPressed, pointerReleased, longPointerPress, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, 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, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, deinitialize, initComponent, isInitialized, setInitialized, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, 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, cancelRepaints, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

Label

public Label(String text)
Constructs a new label with the specified string of text, left justified.

Parameters

text String
the string that the label presents.

Label

public Label(String text, String uiid)
Constructs a new label with the specified string of text and uiid

Parameters

text String
the string that the label presents.
uiid String
the uiid for the label

Label

public Label()
Construct an empty label

Label

public Label(Image icon)
Constructs a new label with the specified icon

Parameters

icon Image
the image that the label presents.

Label

public Label(Image icon, String uiid)
Constructs a new label with the specified icon and UIID

Parameters

icon Image
the image that the label presents.
uiid String
the uiid for the label

Label

public Label(String text, Image icon, String uiid)
Constructs a new label with the specified icon text and UIID

Parameters

text String
the text of the label
icon Image
the image that the label presents.
uiid String
the uiid for the label

Label

public Label(String text, Image icon)
Constructs a new label with the specified icon and text

Parameters

text String
the text of the label
icon Image
the image that the label presents.

Method details

getDefaultGap

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

Returns

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

setDefaultGap

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

Parameters

gap int
the gap in pixels

isDefaultTickerEnabled

public static boolean isDefaultTickerEnabled()
Allows disabling/enabling tickers globally

Returns

the defaultTickerEnabled

setDefaultTickerEnabled

public static void setDefaultTickerEnabled(boolean aDefaultTickerEnabled)
Allows disabling/enabling tickers globally

Parameters

aDefaultTickerEnabled boolean
the defaultTickerEnabled to set

laidOut

protected void laidOut()
This is a callback method to inform the Component when it’s been laidout on the parent Container This is overriden for auto size mode

getBadgeText

public String getBadgeText()
Gets the text to be used in a badge on this label.

Returns

the badge text to be used on this label. May return if no text is set.

setBadgeText

public void setBadgeText(String badgeText)
Sets the badge text to be used on this label. Badges are rendered in the upper right corner of the label inside round border. The style of the badge can be configured using #setBadgeUIID(java.lang.String), but the default style uses the “Badge” UIID, which, by default, uses white text on a red round border background.

Parameters

badgeText String
The text to include in the badge. null or empty strings will result in the badge not being rendered.

setBadgeUIID

public void setBadgeUIID(String badgeUIID)
Sets the style that should be used for rendering badges. By default it will use the “Badge” UIID, which rendered 1.5mm white text on a red round border.

Parameters

badgeUIID String
The UIID to use for the badge.

getBadgeStyleComponent

public Component getBadgeStyleComponent()
Gets a component that can be used for the style of the badge.

Returns

The component whose style can be used to style the badge. May return null if none set.

getIconStyleComponent

public Component getIconStyleComponent()
Gets the component that should be used for styling material the material icon. If #setIconUIID(java.lang.String) has been used to set a custom UIID for the icon, then this will return a component with that UIID. Otherwise this will just return this component itself.

Returns

The component to use for styling the material icon.

setFontIcon

public void setFontIcon(Font font, char c)
This method is shorthand for Font, char, float)

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

setFontIcon

public void setFontIcon(char c)
Sets an icon font using either the same icon font that was used to set the icon font last, or using the font from the icon UIID.

Parameters

c char
The character to render in the font.

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

getBaselineResizeBehavior

public int getBaselineResizeBehavior()
Returns a constant indicating how the baseline varies with the size of the component.

Returns

one of BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET or BRB_OTHER

getBaseline

public int getBaseline(int width, int height)
The baseline for the component text according to which it should be aligned with other components for best visual look.

Parameters

width int
the component width
height int
the component height

Returns

baseline value from the top of 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

refreshTheme

public void refreshTheme(boolean merge)
Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!

Parameters

merge boolean
indicates if the current styles should be merged with the new styles

initLaf

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

getText

public String getText()
Returns the label text

Returns

the label text

setText

public void setText(String text)
Sets the Label text

Parameters

text String
the string that the label presents.

getIcon

public Image getIcon()
Returns the labels icon

Returns

the labels icon

setIcon

public void setIcon(Image icon)
Sets the Label icon, if the icon is unmodified a repaint would not be triggered

Parameters

icon Image
the image that the label presents.

getVerticalAlignment

public int getVerticalAlignment()
Returns the vertical alignment of the Label, this will only work when the icon is in the side of the text and not above or below it. The valign property is only relevant relatively to the icon and not the entire label, this will only work when there is an icon

Returns

the vertical alignment of the Label one of: CENTER, TOP, BOTTOM, BASELINE

setVerticalAlignment

public void setVerticalAlignment(int valign)
Sets the vertical alignment of the Label to one of: CENTER, TOP, BOTTOM, BASELINE The valign property is only relevant relatively to the icon and not the entire label, this will only work when there is an icon

Parameters

valign int
alignment value

getAlignment

public int getAlignment()
Deprecated. use Style.getAlignment instead
Returns the alignment of the Label

Returns

the alignment of the Label one of: CENTER, LEFT, RIGHT

setAlignment

public void setAlignment(int align)
Deprecated. use Style.setAlignment instead
Sets the Alignment of the Label to one of: CENTER, LEFT, RIGHT

Parameters

align int
alignment value

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)

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

paramString

protected String paramString()
Returns a string representing the state of this component. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns

a string representation of this component’s state

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics

getMaxAutoSize

public float getMaxAutoSize()
Allows us to limit the maximum size for the autosize mode

Returns

the maximum font size in millimeters

setMaxAutoSize

public void setMaxAutoSize(float maxSize)
Allows us to limit the maximum size for the autosize mode

Parameters

maxSize float
the maximum font size in millimeters

getMinAutoSize

public float getMinAutoSize()
Allows us to limit the minimum size for the autosize mode

Returns

the minimum font size in millimeters

setMinAutoSize

public void setMinAutoSize(float minSize)
Allows us to limit the minimum size for the autosize mode

Parameters

minSize float
the minimum font size in millimeters

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

getShiftText

public int getShiftText()
Simple getter to return how many pixels to shift the text inside the Label

Returns

number of pixels to shift

setShiftText

public void setShiftText(int shiftText)
This method shifts the text from it’s position in pixels. The value can be positive/negative to move the text to the right/left

Parameters

shiftText int
The number of pixels to move the text

shouldTickerStart

public boolean shouldTickerStart()
Returns true if a ticker should be started since there is no room to show the text in the label.

Returns

true if a ticker should start running

startTicker

public void startTicker()
This method will start the text ticker

startTicker

public void startTicker(long delay, boolean rightToLeft)
This method will start the text ticker

Parameters

delay long
the delay in millisecods between animation intervals
rightToLeft boolean
if true move the text to the left

stopTicker

public void stopTicker()
Stops the text ticker

isTickerRunning

public boolean isTickerRunning()
Returns true if the ticker is running

Returns

true if the ticker is running

isTickerEnabled

public boolean isTickerEnabled()
This method return true if the ticker is enabled on this Label

Returns

tickerEnabled

setTickerEnabled

public void setTickerEnabled(boolean tickerEnabled)
Sets the Label to allow ticking of the text. By default is true

isEndsWith3Points

public boolean isEndsWith3Points()
If the Label text is too long fit the text to the widget and adds “...” points at the end. By default this is set to false for faster performance.

Returns

true if this Label adds “…” when the text is too long

setEndsWith3Points

public void setEndsWith3Points(boolean endsWith3Points)
If the Label text is too long fit the text to the widget and adds “...” points at the end. By default this is set to false for faster performance.

Parameters

endsWith3Points boolean
true if text should add “…” at the end

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

getMask

public Object getMask()
Returns the mask matching the given image

Returns

the mask for the given label

setMask

public void setMask(Object mask)
A mask image can be applied to the label (see the image mask method for details) which allows for things like rounded image appearance etc.

Parameters

mask Object
the mask returned from the image object

getMaskName

public String getMaskName()
Determines the name of the mask from the image constants thus allowing the mask to be applied from the theme

Returns

the maskName

setMaskName

public void setMaskName(String maskName)
Determines the name of the mask from the image constants thus allowing the mask to be applied from the theme

Parameters

maskName String
the maskName to set

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

getMaskedIcon

public Image getMaskedIcon()
If a mask is applied returns the icon with a mask, otherwise returns the icon

Returns

the icon masked or otherwise

getBindablePropertyNames

public String[] getBindablePropertyNames()
Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound

Returns

a string array of property names or null

getBindablePropertyTypes

public Class[] getBindablePropertyTypes()
Returns the types of the properties that are bindable within this component

Returns

the class for binding

bindProperty

public void bindProperty(String prop, BindTarget target)
Deprecated. uses the deprecated BindTarget interface
Binds the given property name to the given bind target

Parameters

prop String
the property name
target BindTarget
the target binder

unbindProperty

public void unbindProperty(String prop, BindTarget target)
Deprecated. uses the deprecated BindTarget interface
Removes a bind target from the given property name

Parameters

prop String
the property names
target BindTarget
the target binder

getBoundPropertyValue

public Object getBoundPropertyValue(String prop)
Allows the binding code to extract the value of the property

Parameters

prop String
the property

Returns

the value for the property

setBoundPropertyValue

public void setBoundPropertyValue(String prop, Object value)
Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!

Parameters

prop String
the property whose value should be set
value Object
the value

isShouldLocalize

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

Returns

the shouldLocalize value

setShouldLocalize

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

Parameters

shouldLocalize boolean
the shouldLocalize to set

getShiftMillimeters

public int getShiftMillimeters()
Deprecated. Use #getShiftMillimetersF()
Returns the number of millimeters that should be shifted in tickering rounded to nearest int.

Returns

the shiftMillimeters

setShiftMillimeters

public void setShiftMillimeters(int shiftMillimeters)
Sets the millimeters that should be shifted in tickering

Parameters

shiftMillimeters int
the shiftMillimeters to set

setShiftMillimeters

public void setShiftMillimeters(float shiftMillimeters)
Sets the millimeters that should be shifted in tickering as a float.

Parameters

shiftMillimeters float
the shiftMillimeters to set

getShiftMillimetersF

public float getShiftMillimetersF()
Returns the number of millimeters that should be shifted in tickering as a float.

isShowEvenIfBlank

public boolean isShowEvenIfBlank()
By default labels and subclasses become 0 sized when they are blank even ignoring their padding setting this to true makes the padding take effect even in a blank field.

Returns

the showEvenIfBlank

setShowEvenIfBlank

public final void setShowEvenIfBlank(boolean showEvenIfBlank)
By default labels and subclasses become 0 sized when they are blank even ignoring their padding setting this to true makes the padding take effect even in a blank field.

Parameters

showEvenIfBlank boolean
the showEvenIfBlank to set

getStringWidth

public int getStringWidth(Font fnt)
This method is equivalent to label.getStyle().getFont().stringWidth(label.getText()) but its faster

Parameters

fnt Font
the font is passed as an optimization to save a call to getStyle

Returns

the string width

isLegacyRenderer

public boolean isLegacyRenderer()
Fallback to the old default look and feel renderer for cases where compatibility is essential

Returns

the legacyRenderer

setLegacyRenderer

public void setLegacyRenderer(boolean legacyRenderer)
Fallback to the old default look and feel renderer for cases where compatibility is essential

Parameters

legacyRenderer boolean
the legacyRenderer to set

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.

isAutoSizeMode

public boolean isAutoSizeMode()
Autosize mode automatically shrinks/grows the font of the label to fit in the available width, it carries a noticeable performance penalty and we recommend you avoid using it unless absolutely necessary

Returns

the autoSizeMode

setAutoSizeMode

public void setAutoSizeMode(boolean autoSizeMode)
Autosize mode automatically shrinks/grows the font of the label to fit in the available width, it carries a noticeable performance penalty and we recommend you avoid using it unless absolutely necessary

Parameters

autoSizeMode boolean
the autoSizeMode to set

isTextSelectionEnabled

public boolean isTextSelectionEnabled()
Returns true if text selection is enabled on this label. Default is false. To enable text selection, you must enable text selection on the Form with Form#getTextSelection() and TextSelection#setEnabled(boolean), and also ensure that the label’s text selection is enabled via #setTextSelectionEnabled(boolean).

setTextSelectionEnabled

public void setTextSelectionEnabled(boolean enabled)
Enables text selection on this label. Text selection must also be enabled on the Form in order to text selection to be activated.

getTextSelectionSupport

public TextSelection.TextSelectionSupport getTextSelectionSupport()
Returns text selection support object for this component. Only used by components that support text selection (e.g. Labels, un-editable text fields, etc..).

Returns

text selection support object

getIconUIID

public String getIconUIID()
Gets the UIID used for styling material icons on this component.

setIconUIID

public void setIconUIID(String uiid)
Sets a UIID to be used for the material icon style.

Parameters

uiid String
The uiid to use for the material icon style.