public class Label extends Widget
Unlike most scene2d.ui widgets, label can be scaled and rotated using the actor's scale, rotation, and origin. This only affects drawing, other scene2d.ui widgets will still use the unscaled and unrotated bounds of the label. Note that a scaled or rotated label causes a SpriteBatch flush when it is drawn, so should be used relatively sparingly.
The preferred size of the label is determined by the actual text bounds, unless word wrap is enabled.
| Modifier and Type | Class and Description |
|---|---|
static class |
Label.LabelStyle
The style for a label, see
Label. |
| Constructor and Description |
|---|
Label(java.lang.CharSequence text,
Label.LabelStyle style) |
Label(java.lang.CharSequence text,
Skin skin) |
Label(java.lang.CharSequence text,
Skin skin,
java.lang.String styleName) |
Label(java.lang.CharSequence text,
Skin skin,
java.lang.String fontName,
Color color)
Creates a label, using a
Label.LabelStyle that has a BitmapFont with the specified name from the skin and the specified
color. |
Label(java.lang.CharSequence text,
Skin skin,
java.lang.String fontName,
java.lang.String colorName)
Creates a label, using a
Label.LabelStyle that has a BitmapFont with the specified name and the specified color from the
skin. |
| Modifier and Type | Method and Description |
|---|---|
void |
draw(SpriteBatch batch,
float parentAlpha)
If this method is overridden, the super method or
Widget.validate() should be called to ensure the widget is laid out. |
float |
getFontScaleX() |
float |
getFontScaleY() |
float |
getPrefHeight() |
float |
getPrefWidth() |
Label.LabelStyle |
getStyle()
Returns the label's style.
|
java.lang.CharSequence |
getText() |
BitmapFont.TextBounds |
getTextBounds() |
void |
invalidate()
Invalidates this actor's layout, causing
Layout.layout() to happen the next time Layout.validate() is called. |
void |
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child,
calls
Layout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child. |
void |
setAlignment(int wrapAlign) |
void |
setAlignment(int labelAlign,
int lineAlign) |
void |
setFontScale(float fontScale) |
void |
setFontScale(float fontScaleX,
float fontScaleY) |
void |
setFontScaleX(float fontScaleX) |
void |
setFontScaleY(float fontScaleY) |
void |
setStyle(Label.LabelStyle style) |
void |
setText(java.lang.CharSequence newText) |
void |
setWrap(boolean wrap)
If false, the text will only wrap where it contains newlines (\n).
|
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validateact, addAction, addCaptureListener, addListener, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, hit, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translatepublic Label(java.lang.CharSequence text,
Skin skin)
public Label(java.lang.CharSequence text,
Skin skin,
java.lang.String styleName)
public Label(java.lang.CharSequence text,
Skin skin,
java.lang.String fontName,
Color color)
Label.LabelStyle that has a BitmapFont with the specified name from the skin and the specified
color.public Label(java.lang.CharSequence text,
Skin skin,
java.lang.String fontName,
java.lang.String colorName)
Label.LabelStyle that has a BitmapFont with the specified name and the specified color from the
skin.public Label(java.lang.CharSequence text,
Label.LabelStyle style)
public void setStyle(Label.LabelStyle style)
public Label.LabelStyle getStyle()
setStyle(LabelStyle) is
called.public void setText(java.lang.CharSequence newText)
newText - May be null.public java.lang.CharSequence getText()
public void invalidate()
LayoutLayout.layout() to happen the next time Layout.validate() is called. This
method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred,
maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).invalidate in interface Layoutinvalidate in class Widgetpublic void layout()
LayoutLayout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child.
This method should almost never be called directly, instead Layout.validate() should be used.public void draw(SpriteBatch batch, float parentAlpha)
WidgetWidget.validate() should be called to ensure the widget is laid out.public float getPrefWidth()
getPrefWidth in interface LayoutgetPrefWidth in class Widgetpublic float getPrefHeight()
getPrefHeight in interface LayoutgetPrefHeight in class Widgetpublic BitmapFont.TextBounds getTextBounds()
public void setWrap(boolean wrap)
public void setAlignment(int wrapAlign)
wrapAlign - Aligns each line of text horizontally and all the text vertically.Alignpublic void setAlignment(int labelAlign,
int lineAlign)
labelAlign - Aligns all the text with the label widget.lineAlign - Aligns each line of text (left, right, or center).Alignpublic void setFontScale(float fontScale)
public void setFontScale(float fontScaleX,
float fontScaleY)
public float getFontScaleX()
public void setFontScaleX(float fontScaleX)
public float getFontScaleY()
public void setFontScaleY(float fontScaleY)