public class Label extends Widget
This example shows a simple label:
Label label = new Label("Hello World");
This example shows a styled label:
Label label = new Label("Hello World"); CascadingStylesheet stylesheet = new CascadingStylesheet(); desktop.setStylesheet(stylesheet); EditableStyle labelStyle = stylesheet.getSelectorStyle(new TypeSelector(Label.class)); labelStyle.setColor(Colors.NAVY); labelStyle.setBackground(new RectangularBackground(Colors.CYAN)); labelStyle.setFont(Font.getFont("/fonts/source_sans_pro_24.ejf"));
NO_CONSTRAINT
Modifier | Constructor and Description |
---|---|
|
Label()
Creates a label with an empty text.
|
|
Label(String text)
Creates a label with the given text to display.
|
protected |
Label(String text,
boolean enabled)
Creates a label with the given text to display and its enabled state.
|
Modifier and Type | Method and Description |
---|---|
protected void |
computeContentOptimalSize(Size size)
Computes the optimal size of the widget.
|
String |
getText()
Gets the text displayed on this label.
|
protected void |
renderContent(GraphicsContext g,
int contentWidth,
int contentHeight)
Renders the content of the widget without the border, margin and padding specified in the style.
|
void |
setText(String text)
Sets the text to display on this label.
|
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getContentBounds, getDesktop, getHeight, getParent, getStyle, getWidgetAt, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle, updateStyle
public Label()
public Label(String text)
text
- the text to display.protected Label(String text, boolean enabled)
text
- the text to display.enabled
- true
if this label is to be enabled, false
otherwise.protected void computeContentOptimalSize(Size size)
Widget
This method does not consider the border, margin, padding and dimension specified in the style.
The given size is the available size for this widget in its parent. A width or a height equal to
Widget#NO_CONSTRAINT
means that there is no constraint on this dimension.
The given size is modified to set the optimal size.
computeContentOptimalSize
in class Widget
size
- the size available for the content.public String getText()
protected void renderContent(GraphicsContext g, int contentWidth, int contentHeight)
Widget
The given graphics context is translated and clipped according to the given bounds (the border, margin and padding are applied on this graphics context before).
renderContent
in class Widget
g
- the graphics context where to render the content of the widget.contentWidth
- the width of the content area.contentHeight
- the height of the content area.public void setText(String text)
text
- the text to display on this label.