Class Label
- All Implemented Interfaces:
Component, TextGUIElement
- Direct Known Subclasses:
AnimatedLabel, FileDialog.FileSystemLocationLabel
Label is a simple read-only text display component. It supports customized colors and multi-line text.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TextColorprivate TextColorprivate TerminalSizeprivate Integerprivate String[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds an additional SGR style to use when drawing the label, in case it wasn't enabled by the themeprotected ComponentRenderer<Label> 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).Returns the background color used when drawing the label, ornullif the color is read from the current theme.protected TerminalSizegetBounds(String[] lines, TerminalSize currentBounds) Returns the area, in terminal columns and rows, required to fully draw the lines passed in.Returns the foreground color used when drawing the label, ornullif the color is read from the current theme.Returns the limit how wide the label can grow.getText()Returns the text this label is displaying.removeStyle(SGR sgr) Removes an additional SGR style used when drawing the label, previously added byaddStyle(..).setBackgroundColor(TextColor backgroundColor) Overrides the current theme's background color and use the one specified.setForegroundColor(TextColor foregroundColor) Overrides the current theme's foreground color and use the one specified.setLabelWidth(Integer labelWidth) Use this method to limit how wide the label can grow.protected voidProtected access to set the internal representation of the text in this label, to be used by sub-classes of label in certain cases wheresetText(..)doesn't work.voidUpdates the text this label is displayingprotected String[]splitIntoMultipleLines(String text) Utility method for taking a string and turning it into an array of lines.Methods inherited from class AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
Field Details
-
lines
-
labelWidth
-
labelSize
-
foregroundColor
-
backgroundColor
-
additionalStyles
-
-
Constructor Details
-
Label
Main constructor, creates a new Label displaying a specific text.- Parameters:
text- Text the label will display
-
-
Method Details
-
setLines
Protected access to set the internal representation of the text in this label, to be used by sub-classes of label in certain cases wheresetText(..)doesn't work. In general, you probably want to stick tosetText(..)instead of this method unless you have a good reason not to.- Parameters:
lines- New lines this label will display
-
setText
Updates the text this label is displaying- Parameters:
text- New text to display
-
getText
Returns the text this label is displaying. Multi-line labels will have their text concatenated with \n, even if they were originally set using multi-line text having \r\n as line terminators.- Returns:
- String of the text this label is displaying
-
splitIntoMultipleLines
Utility method for taking a string and turning it into an array of lines. This method is used in order to deal with line endings consistently.- Parameters:
text- Text to split- Returns:
- Array of strings that forms the lines of the original string
-
getBounds
Returns the area, in terminal columns and rows, required to fully draw the lines passed in.- Parameters:
lines- Lines to measure the size ofcurrentBounds- Optional (can passnull) 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 newTerminalSizeobjects every time- Returns:
- Size that is required to draw the lines
-
setForegroundColor
Overrides the current theme's foreground color and use the one specified. If called withnull, the override is cleared and the theme is used again.- Parameters:
foregroundColor- Foreground color to use when drawing the label, ifnullthen use the theme's default- Returns:
- Itself
-
getForegroundColor
Returns the foreground color used when drawing the label, ornullif the color is read from the current theme.- Returns:
- Foreground color used when drawing the label, or
nullif the color is read from the current theme.
-
setBackgroundColor
Overrides the current theme's background color and use the one specified. If called withnull, the override is cleared and the theme is used again.- Parameters:
backgroundColor- Background color to use when drawing the label, ifnullthen use the theme's default- Returns:
- Itself
-
getBackgroundColor
Returns the background color used when drawing the label, ornullif the color is read from the current theme.- Returns:
- Background color used when drawing the label, or
nullif the color is read from the current theme.
-
addStyle
-
removeStyle
-
setLabelWidth
Use this method to limit how wide the label can grow. If set tonullthere 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 tonull, 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.- Parameters:
labelWidth- Eithernullor 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 begin- Returns:
- Itself
-
getLabelWidth
Returns the limit how wide the label can grow. If set tonullor 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 tonull, 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.- Returns:
- Either
nullor 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 begin
-
createDefaultRenderer
Description copied from class:AbstractComponentWhen 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). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRendererin classAbstractComponent<Label>- Returns:
- Renderer to use when sizing and drawing this component
-