java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.LabelBase<T>
         ↳ com.google.gwt.user.client.ui.Label
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A widget that contains arbitrary text, not interpreted as HTML. This widget uses a <div> element, causing it to be displayed with block layout.

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by setDirectionEstimator(boolean) or passing a DirectionEstimator parameter to the constructor, and is off by default.

CSS Style Rules

  • .gwt-Label { }

Example

{@example com.google.gwt.examples.HTMLExample}

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Fields
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
[Expand]
Inherited Fields
From interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasHorizontalAlignment
Public Constructors
Label()
Creates an empty label.
Label(String text)
Creates a label with the specified text.
Label(String text, HasDirection.Direction dir)
Creates a label with the specified text and direction.
Label(String text, DirectionEstimator directionEstimator)
Creates a label with the specified text and a default direction estimator.
Label(String text, boolean wordWrap)
Creates a label with the specified text.
Protected Constructors
Label(Element element)
This constructor may be used by subclasses to explicitly use an existing element.
Public Methods
HandlerRegistration addClickHandler(ClickHandler handler)
Adds a ClickEvent handler.
void addClickListener(ClickListener listener)
This method is deprecated. Use addClickHandler(ClickHandler) instead
HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Adds a DoubleClickEvent handler.
HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler)
Adds a GestureChangeEvent handler.
HandlerRegistration addGestureEndHandler(GestureEndHandler handler)
Adds a GestureEndEvent handler.
HandlerRegistration addGestureStartHandler(GestureStartHandler handler)
Adds a GestureStartEvent handler.
HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
Adds a MouseDownEvent handler.
void addMouseListener(MouseListener listener)
HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
Adds a MouseMoveEvent handler.
HandlerRegistration addMouseOutHandler(MouseOutHandler handler)
Adds a MouseOutEvent handler.
HandlerRegistration addMouseOverHandler(MouseOverHandler handler)
Adds a MouseOverEvent handler.
HandlerRegistration addMouseUpHandler(MouseUpHandler handler)
Adds a MouseUpEvent handler.
HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
Adds a MouseWheelEvent handler.
void addMouseWheelListener(MouseWheelListener listener)
This method is deprecated. Use addMouseWheelHandler(MouseWheelHandler) instead
HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler)
Adds a TouchCancelEvent handler.
HandlerRegistration addTouchEndHandler(TouchEndHandler handler)
Adds a TouchEndEvent handler.
HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler)
Adds a TouchMoveEvent handler.
HandlerRegistration addTouchStartHandler(TouchStartHandler handler)
Adds a TouchStartEvent handler.
LeafValueEditor<String> asEditor()
Returns the Editor encapsulated by the view object.
HasDirection.Direction getDirection()
This method is deprecated. Use getTextDirection() instead
String getText()
Gets this object's text.
HasDirection.Direction getTextDirection()
Gets the direction of this object's text.
void removeClickListener(ClickListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by addClickHandler(ClickHandler) instead
void removeMouseListener(MouseListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by an add*Handler method instead
void removeMouseWheelListener(MouseWheelListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by addMouseWheelHandler(MouseWheelHandler) instead
void setDirection(HasDirection.Direction direction)
This method is deprecated. Use setDirectionEstimator(boolean) and / or pass explicit direction to setText(String) instead
void setText(String text)
Sets the label's content to the given text.
void setText(String text, HasDirection.Direction dir)
Sets the label's content to the given text, applying the given direction.
static Label wrap(Element element)
Creates a Label widget that wraps an existing <div> or <span> element.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.LabelBase
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.editor.client.IsEditor
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.dom.client.HasGestureChangeHandlers
From interface com.google.gwt.event.dom.client.HasGestureEndHandlers
From interface com.google.gwt.event.dom.client.HasGestureStartHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.dom.client.HasTouchCancelHandlers
From interface com.google.gwt.event.dom.client.HasTouchEndHandlers
From interface com.google.gwt.event.dom.client.HasTouchMoveHandlers
From interface com.google.gwt.event.dom.client.HasTouchStartHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.i18n.client.HasDirection
From interface com.google.gwt.i18n.shared.HasDirectionEstimator
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasDirectionalText
From interface com.google.gwt.user.client.ui.HasHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.HasWordWrap
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents

Fields

public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR

Public Constructors

public Label ()

Creates an empty label.

public Label (String text)

Creates a label with the specified text.

Parameters
text the new label's text

public Label (String text, HasDirection.Direction dir)

Creates a label with the specified text and direction.

Parameters
text the new label's text
dir the text's direction. Note that DEFAULT means direction should be inherited from the widget's parent element.

public Label (String text, DirectionEstimator directionEstimator)

Creates a label with the specified text and a default direction estimator.

Parameters
text the new label's text
directionEstimator A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.

public Label (String text, boolean wordWrap)

Creates a label with the specified text.

Parameters
text the new label's text
wordWrap false to disable word wrapping

Protected Constructors

protected Label (Element element)

This constructor may be used by subclasses to explicitly use an existing element. This element must be either a <div> or <span> element.

Parameters
element the element to be used

Public Methods

public HandlerRegistration addClickHandler (ClickHandler handler)

Adds a ClickEvent handler.

Parameters
handler the click handler
Returns

public void addClickListener (ClickListener listener)

This method is deprecated.
Use addClickHandler(ClickHandler) instead

Adds a listener interface to receive click events.

Parameters
listener the listener interface to add

public HandlerRegistration addDoubleClickHandler (DoubleClickHandler handler)

Adds a DoubleClickEvent handler.

Parameters
handler the double click handler
Returns

public HandlerRegistration addGestureChangeHandler (GestureChangeHandler handler)

Adds a GestureChangeEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addGestureEndHandler (GestureEndHandler handler)

Adds a GestureEndEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addGestureStartHandler (GestureStartHandler handler)

Adds a GestureStartEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addMouseDownHandler (MouseDownHandler handler)

Adds a MouseDownEvent handler.

Parameters
handler the mouse down handler
Returns

public void addMouseListener (MouseListener listener)

This method is deprecated.
Use addMouseOverHandler(MouseOverHandler), addMouseMoveHandler(MouseMoveHandler), addMouseDownHandler(MouseDownHandler), addMouseUpHandler(MouseUpHandler) and addMouseOutHandler(MouseOutHandler) instead

Adds a listener interface to receive mouse events.

Parameters
listener the listener interface to add

public HandlerRegistration addMouseMoveHandler (MouseMoveHandler handler)

Adds a MouseMoveEvent handler.

Parameters
handler the mouse move handler
Returns

public HandlerRegistration addMouseOutHandler (MouseOutHandler handler)

Adds a MouseOutEvent handler.

Parameters
handler the mouse out handler
Returns

public HandlerRegistration addMouseOverHandler (MouseOverHandler handler)

Adds a MouseOverEvent handler.

Parameters
handler the mouse over handler
Returns

public HandlerRegistration addMouseUpHandler (MouseUpHandler handler)

Adds a MouseUpEvent handler.

Parameters
handler the mouse up handler
Returns

public HandlerRegistration addMouseWheelHandler (MouseWheelHandler handler)

Adds a MouseWheelEvent handler.

Parameters
handler the mouse wheel handler
Returns

public void addMouseWheelListener (MouseWheelListener listener)

This method is deprecated.
Use addMouseWheelHandler(MouseWheelHandler) instead

public HandlerRegistration addTouchCancelHandler (TouchCancelHandler handler)

Adds a TouchCancelEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addTouchEndHandler (TouchEndHandler handler)

Adds a TouchEndEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addTouchMoveHandler (TouchMoveHandler handler)

Adds a TouchMoveEvent handler.

Parameters
handler the mouse down handler
Returns

public HandlerRegistration addTouchStartHandler (TouchStartHandler handler)

Adds a TouchStartEvent handler.

Parameters
handler the mouse down handler
Returns

public LeafValueEditor<String> asEditor ()

Returns the Editor encapsulated by the view object.

Returns

public HasDirection.Direction getDirection ()

This method is deprecated.
Use getTextDirection() instead

Gets the widget element's direction.

Returns
  • RTL if the directionality is right-to-left, LTR if the directionality is left-to-right, or DEFAULT if the directionality is not explicitly specified

public String getText ()

Gets this object's text.

Returns
  • the object's text

public HasDirection.Direction getTextDirection ()

Gets the direction of this object's text.

Returns
  • the direction of this object's text

public void removeClickListener (ClickListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by addClickHandler(ClickHandler) instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void removeMouseListener (MouseListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by an add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void removeMouseWheelListener (MouseWheelListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by addMouseWheelHandler(MouseWheelHandler) instead

public void setDirection (HasDirection.Direction direction)

This method is deprecated.
Use setDirectionEstimator(boolean) and / or pass explicit direction to setText(String) instead

Sets the widget element's direction.

Parameters
direction RTL if the directionality should be set to right-to-left, LTR if the directionality should be set to left-to-right DEFAULT if the directionality should not be explicitly set

public void setText (String text)

Sets the label's content to the given text.

Doesn't change the widget's direction or horizontal alignment if directionEstimator is null. Otherwise, the widget's direction is set using the estimator, and its alignment may therefore change as described in setText(String, Direction).

Parameters
text the widget's new text

public void setText (String text, HasDirection.Direction dir)

Sets the label's content to the given text, applying the given direction.

This will have the following effect on the horizontal alignment:

  • If the automatic alignment setting is ALIGN_CONTENT_START or ALIGN_CONTENT_END, the horizontal alignment will be set to match the start or end edge, respectively, of the new direction (the dir parameter). If that is DEFAULT, the locale direction is used.
  • Otherwise, the horizontal alignment value is not changed, but the effective alignment may nevertheless change according to the usual HTML rules, i.e. it will match the start edge of the new direction if the widget element is a <div> and has no explicit alignment value even by inheritance.

Parameters
text the widget's new text
dir the text's direction. Note: Direction.DEFAULT means direction should be inherited from the widget's parent element.

public static Label wrap (Element element)

Creates a Label widget that wraps an existing <div> or <span> element. This element must already be attached to the document. If the element is removed from the document, you must call detachNow(Widget).

Parameters
element the element to be wrapped