public class Label extends Control implements TextControl
Note: this class does not do automatic parse of the text. However, you can use a handy method to parse the text that you want to display: see the totalcross.sys.Convert.insertLineBreak method.
Here is an example showing a label being used:
public class MyProgram extends MainWindow { public void initUI() { add(new Label("Value:"), LEFT, TOP); }
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
int |
align
The text alignment; possible values are LEFT, RIGHT, CENTER, FILL (justifies the text).
|
protected int |
alpha |
boolean |
autoSplit
Set to true to let the label split its text based on the width every time its width
changes.
|
int |
backgroundType
The type of background of this Label (defaults to SOLID_BACKGROUND).
|
int |
borderColor
Set to a color to let this Label have a border with that color.
|
int |
firstGradientColor
The first color used in GRADIENT backgrounds.
|
static byte |
HORIZONTAL_GRADIENT_BACKGROUND
Specifies a horizontal 3d-gradient background for this Label.
|
protected java.lang.String[] |
lines |
boolean |
pageScroll
Set to false if you want to scroll the text a line at a time instead of a page at a time.
|
java.lang.String |
preferredWidthText
By default, the getPreferredWidth uses the current text to compute the width.
|
int |
secondGradientColor
The second color used in GRADIENT backgrounds.
|
static byte |
SOLID_BACKGROUND
Specifies a solid background for this button (the default).
|
protected java.lang.String |
text
The String with the full text (not splitted)
|
boolean |
useFillAsPreferred
Set automatically to true when an empty string is passed in the constructor.
|
int |
vAlign
The vertical alignment.
|
static byte |
VERTICAL_GRADIENT_BACKGROUND
Specifies a vertical gradient background for this Label.
|
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
Label()
Creates an empty label, using FILL as the preferred width.
|
Label(java.lang.String text)
Creates a label displaying the given text.
|
Label(java.lang.String text,
int align)
Creates a label displaying the given text with the given alignment.
Supports inverted text, multiple lines and is scrollable by default. |
Label(java.lang.String text,
int align,
int fore,
boolean bold)
Creates a label with the given text, alignment, foreground color, and if the font is bold or not.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canScroll(boolean down)
Returns if the label can scroll in the given direction.
|
void |
clear()
This method does nothing: clear a label is usually not a desired action.
|
int |
getAlpha()
Gets the alpha applied to the text color of this object
|
int |
getLineCount()
Return the number of lines of this label.
|
int |
getLinesPerPage()
Return the number of lines per page of this label.
|
int |
getMaxTextWidth()
Returns the maximum text width for the lines of this Label.
|
int |
getPreferredHeight()
Returns the preffered height of this control.
|
int |
getPreferredWidth()
Returns the preffered width of this control.
|
java.lang.String |
getText()
Gets the text that is displayed in the label.
|
boolean |
isMarqueeRunning()
Returns true if the marquee is running.
|
protected void |
onBoundsChanged(boolean screenChanged)
Called after a setRect.
|
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has
been added to a Container.
|
void |
onEvent(Event e)
Called to process key, pen, control and other posted events.
|
protected void |
onFontChanged()
Called after a setFont
|
void |
onPaint(Graphics g)
Called by the system to draw the button.
|
boolean |
scroll(boolean down)
Scroll one page.
|
void |
scrollTo(int line)
Scroll to the given line.
|
void |
scrollToBegin()
Scrolls the text to the begining.
|
void |
scrollToEnd()
Scroll the text to the end.
|
void |
set3d(boolean on)
Draws the label with a 3d effect.
|
void |
setAlpha(int alpha)
Set the alpha value to be used with the text of this object (0 to 255)
|
void |
setHighlighted(boolean on)
Highlights the text, i.e., paints the text in all directions with a brighter color, then centered, with the foreground color.
|
void |
setHighlightedColor(int c)
The color used when highlighting is on.
|
void |
setInsets(int left,
int right,
int top,
int bottom)
Defines a space to be placed around the text of this label.
|
void |
setInvert(boolean on)
Inverts the back and fore colors.
|
void |
setMarqueeText(java.lang.String text,
int delay,
int loopCount,
int step)
Shows this label as a horizontal marquee.
|
void |
setText(java.lang.String text)
Sets the text that is displayed in the label.
|
void |
split(int maxWidth)
Splits the text to the given width.
|
void |
stopMarquee()
Stops the marquee, but does not change the current text.
|
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
protected java.lang.String text
protected int alpha
public int align
public boolean pageScroll
protected java.lang.String[] lines
public boolean useFillAsPreferred
public java.lang.String preferredWidthText
Label l = new Label("99"); l.setText("0");... then the preferred width will be computed based on "0", not in "99". To change this behaviour, assign to this field the text that you want to be used to compute the preferred width.
public int borderColor
setInsets(int, int, int, int)
public static final byte SOLID_BACKGROUND
VERTICAL_GRADIENT_BACKGROUND
,
HORIZONTAL_GRADIENT_BACKGROUND
,
Constant Field Valuespublic static final byte VERTICAL_GRADIENT_BACKGROUND
SOLID_BACKGROUND
,
HORIZONTAL_GRADIENT_BACKGROUND
,
Constant Field Valuespublic static final byte HORIZONTAL_GRADIENT_BACKGROUND
VERTICAL_GRADIENT_BACKGROUND
,
SOLID_BACKGROUND
,
Constant Field Valuespublic int backgroundType
firstGradientColor
and secondGradientColor
.HORIZONTAL_GRADIENT_BACKGROUND
,
VERTICAL_GRADIENT_BACKGROUND
,
SOLID_BACKGROUND
,
firstGradientColor
,
secondGradientColor
public int firstGradientColor
public int secondGradientColor
public boolean autoSplit
public int vAlign
Control.TOP
,
Control.CENTER
,
Control.BOTTOM
public Label()
public Label(java.lang.String text)
text
- the to be text displayedjava.lang.NullPointerException
- if text is null.public Label(java.lang.String text, int align, int fore, boolean bold)
public Label(java.lang.String text, int align)
text
- the text displayed; cannot be null, but can be an empty string.align
- the alignmentjava.lang.NullPointerException
- if text is null.java.lang.IllegalArgumentException
- if align value is not either LEFT, RIGHT, CENTER or FILL.align
public void setInsets(int left, int right, int top, int bottom)
public void setMarqueeText(java.lang.String text, int delay, int loopCount, int step)
text
- the text to be displayeddelay
- the timer delay in ms used to scroll the marquee. 100 is a good value.loopCount
- the number of times the text will loop. Set to -1 to loop forever.
When the loop count is reached, the text is cleared.step
- the step in pixels in which the text will be scrolled. If > 0, will
scroll from left to right; if < 0, will scroll from right to left.public boolean isMarqueeRunning()
public void onEvent(Event e)
Control
public void set3d(boolean on)
public void setInvert(boolean on)
public void setHighlighted(boolean on)
setHighlightedColor(int)
public void setHighlightedColor(int c)
c
- The color to be used as highlighted color. Pass -1 to use the default one.setHighlighted(boolean)
public void split(int maxWidth)
autoSplit
public void setText(java.lang.String text)
setText
in interface TextControl
public void stopMarquee()
public java.lang.String getText()
getText
in interface TextControl
public int getPreferredWidth()
getPreferredWidth
in class Control
public int getMaxTextWidth()
public int getPreferredHeight()
getPreferredHeight
in class Control
public int getAlpha()
public void setAlpha(int alpha)
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Control
protected void onFontChanged()
Control
onFontChanged
in class Control
protected void onBoundsChanged(boolean screenChanged)
Control
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public boolean canScroll(boolean down)
public void scrollToBegin()
public void scrollToEnd()
public void scrollTo(int line)
sbVert.setMaximum(lab.getLineCount()); sbVert.setVisibleItems(lab.getLinesPerPage()); sbVert.setUnitIncrement(1); sbVert.setLiveScrolling(true);At the onEvent:
if (event.type == ControlEvent.PRESSED && event.target == sbVert) lab.scrollTo(sbVert.getValue());
public int getLinesPerPage()
public int getLineCount()
public boolean scroll(boolean down)
pageScroll
public void onPaint(Graphics g)