Component
, TextGUIElement
AnimatedLabel
public class Label extends AbstractComponent<Label>
Constructor | Description |
---|---|
Label(String text) |
Main constructor, creates a new Label displaying a specific text.
|
Modifier and Type | Method | Description |
---|---|---|
Label |
addStyle(SGR sgr) |
Adds an additional SGR style to use when drawing the label, in case it wasn't enabled by the theme
|
protected ComponentRenderer<Label> |
createDefaultRenderer() |
When you create a custom component, you need to implement this method and return a Renderer which is responsible
for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).
|
TextColor |
getBackgroundColor() |
Returns the background color used when drawing the label, or
null if the color is read from the current
theme. |
protected TerminalSize |
getBounds(String[] lines,
TerminalSize currentBounds) |
Returns the area, in terminal columns and rows, required to fully draw the lines passed in.
|
TextColor |
getForegroundColor() |
Returns the foreground color used when drawing the label, or
null if the color is read from the current
theme. |
Integer |
getLabelWidth() |
Returns the limit how wide the label can grow.
|
String |
getText() |
Returns the text this label is displaying.
|
Label |
removeStyle(SGR sgr) |
Removes an additional SGR style used when drawing the label, previously added by
addStyle(..) . |
Label |
setBackgroundColor(TextColor backgroundColor) |
Overrides the current theme's background color and use the one specified.
|
Label |
setForegroundColor(TextColor foregroundColor) |
Overrides the current theme's foreground color and use the one specified.
|
Label |
setLabelWidth(Integer labelWidth) |
Use this method to limit how wide the label can grow.
|
protected void |
setLines(String[] lines) |
Protected access to set the internal representation of the text in this label, to be used by sub-classes of label
in certain cases where
setText(..) doesn't work. |
void |
setText(String text) |
Updates the text this label is displaying
|
protected String[] |
splitIntoMultipleLines(String text) |
Utility method for taking a string and turning it into an array of lines.
|
addTo, calculatePreferredSize, draw, getBasePane, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, toBasePane, toGlobal, withBorder
public Label(String text)
text
- Text the label will displayprotected void setLines(String[] lines)
setText(..)
doesn't work. In general, you probably want to stick to
setText(..)
instead of this method unless you have a good reason not to.lines
- New lines this label will displaypublic void setText(String text)
text
- New text to displaypublic String getText()
protected String[] splitIntoMultipleLines(String text)
text
- Text to splitprotected TerminalSize getBounds(String[] lines, TerminalSize currentBounds)
lines
- Lines to measure the size ofcurrentBounds
- Optional (can pass null
) terminal size to use for storing the output values. If the
method is called many times and always returning the same value, passing in an external
reference of this size will avoid creating new TerminalSize
objects every timepublic Label setForegroundColor(TextColor foregroundColor)
null
, the
override is cleared and the theme is used again.foregroundColor
- Foreground color to use when drawing the label, if null
then use the theme's
defaultpublic TextColor getForegroundColor()
null
if the color is read from the current
theme.null
if the color is read from the current
theme.public Label setBackgroundColor(TextColor backgroundColor)
null
, the
override is cleared and the theme is used again.backgroundColor
- Background color to use when drawing the label, if null
then use the theme's
defaultpublic TextColor getBackgroundColor()
null
if the color is read from the current
theme.null
if the color is read from the current
theme.public Label addStyle(SGR sgr)
sgr
- SGR style to enable for this labelpublic Label removeStyle(SGR sgr)
addStyle(..)
. If the
style you are trying to remove is specified by the theme, calling this method will have no effect.sgr
- SGR style to removepublic Label setLabelWidth(Integer labelWidth)
null
there is no limit but if set to a
positive integer then the preferred size will be calculated using word wrapping for lines that are longer than
this label width. This may make the label increase in height as new rows may be requested. Please note that some
layout managers might assign more space to the label and because of this the wrapping might not be as you expect
it. If set to 0, the label will request the same space as if set to null
, but when drawing it will apply
word wrapping instead of truncation in order to fit the label inside the designated area if it's smaller than
what was requested. By default this is set to 0.labelWidth
- Either null
or 0 for no limit on how wide the label can be, where 0 indicates word
wrapping should be used if the assigned area is smaller than the requested size, or a positive
integer setting the requested maximum width at what point word wrapping will beginpublic Integer getLabelWidth()
null
or 0 there is no limit but if set to a
positive integer then the preferred size will be calculated using word wrapping for lines that are longer than
the label width. This may make the label increase in height as new rows may be requested. Please note that some
layout managers might assign more space to the label and because of this the wrapping might not be as you expect
it. If set to 0, the label will request the same space as if set to null
, but when drawing it will apply
word wrapping instead of truncation in order to fit the label inside the designated area if it's smaller than
what was requested.null
or 0 for no limit on how wide the label can be, where 0 indicates word
wrapping should be used if the assigned area is smaller than the requested size, or a positive
integer setting the requested maximum width at what point word wrapping will beginprotected ComponentRenderer<Label> createDefaultRenderer()
AbstractComponent
createDefaultRenderer
in class AbstractComponent<Label>
Copyright © 2020. All rights reserved.