Package ej.widget.basic
Class Label
- java.lang.Object
-
- ej.mwt.Widget
-
- ej.widget.basic.Label
-
- Direct Known Subclasses:
Button
public class Label extends Widget
A label is a widget that displays a text.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"));
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ej.mwt.Widget
Widget.WidgetListener
-
-
Field Summary
-
Fields inherited from class ej.mwt.Widget
DEBUG_WIDGET_ENABLED_CONSTANT, DEBUG_WIDGET_MONITOR_CONSTANT, NO_CONSTRAINT
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcomputeContentOptimalSize(Size size)Computes the optimal size of the widget.StringgetText()Gets the text displayed on this label.protected voidrenderContent(GraphicsContext g, int contentWidth, int contentHeight)Renders the content of the widget without the border, margin and padding specified in the style.voidsetText(String text)Sets the text to display on this label.-
Methods inherited from class ej.mwt.Widget
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, setX, setY, updateStyle
-
-
-
-
Constructor Detail
-
Label
public Label()
Creates a label with an empty text.
-
Label
public Label(String text)
Creates a label with the given text to display.- Parameters:
text- the text to display.
-
Label
protected Label(String text, boolean enabled)
Creates a label with the given text to display and its enabled state.- Parameters:
text- the text to display.enabled-trueif this label is to be enabled,falseotherwise.
-
-
Method Detail
-
getText
public String getText()
Gets the text displayed on this label.- Returns:
- the text displayed on this label.
-
setText
public void setText(String text)
Sets the text to display on this label.- Parameters:
text- the text to display on this label.
-
renderContent
protected void renderContent(GraphicsContext g, int contentWidth, int contentHeight)
Description copied from class:WidgetRenders the content of the widget without the border, margin and padding specified in the style.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).
- Specified by:
renderContentin classWidget- Parameters:
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.
-
computeContentOptimalSize
protected void computeContentOptimalSize(Size size)
Description copied from class:WidgetComputes the optimal size of the 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_CONSTRAINTmeans that there is no constraint on this dimension.The given size is modified to set the optimal size.
- Specified by:
computeContentOptimalSizein classWidget- Parameters:
size- the size available for the content.
-
-