GWT 2.1.0

com.google.gwt.user.client.ui
Class Label

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Label
All Implemented Interfaces:
IsEditor<LeafValueEditor<java.lang.String>>, HasAllMouseHandlers, HasClickHandlers, HasDoubleClickHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasAttachHandlers, HasHandlers, HasDirection, HasDirectionEstimator, EventListener, HasAutoHorizontalAlignment, HasDirectionalText, HasHorizontalAlignment, HasText, HasWordWrap, IsWidget, SourcesClickEvents, SourcesMouseEvents
Direct Known Subclasses:
HTML, InlineLabel

public class Label
extends Widget
implements HasDirectionalText, HasWordWrap, HasDirection, HasClickHandlers, HasDoubleClickHandlers, SourcesClickEvents, SourcesMouseEvents, HasAllMouseHandlers, HasDirectionEstimator, HasAutoHorizontalAlignment, IsEditor<LeafValueEditor<java.lang.String>>

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

CSS Style Rules

Example

public class HTMLExample implements EntryPoint {

  public void onModuleLoad() {
    // Create a Label and an HTML widget.
    Label lbl = new Label("This is just text.  It will not be interpreted "
      + "as <html>.");

    HTML html = new HTML(
      "This is <b>HTML</b>.  It will be interpreted as such if you specify "
        + "the <span style='font-family:fixed'>asHTML</span> flag.", true);

    // Add them to the root panel.
    VerticalPanel panel = new VerticalPanel();
    panel.add(lbl);
    panel.add(html);
    RootPanel.get().add(panel);
  }
}


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Nested classes/interfaces inherited from interface com.google.gwt.i18n.client.HasDirection
HasDirection.Direction
 
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Fields inherited from interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
ALIGN_CONTENT_END, ALIGN_CONTENT_START
 
Fields inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
ALIGN_CENTER, ALIGN_DEFAULT, ALIGN_JUSTIFY, ALIGN_LEFT, ALIGN_LOCALE_END, ALIGN_LOCALE_START, ALIGN_RIGHT
 
Constructor Summary
  Label()
          Creates an empty label.
protected Label(Element element)
          This constructor may be used by subclasses to explicitly use an existing element.
  Label(java.lang.String text)
          Creates a label with the specified text.
  Label(java.lang.String text, boolean wordWrap)
          Creates a label with the specified text.
  Label(java.lang.String text, HasDirection.Direction dir)
          Creates a label with the specified text and direction.
 
Method Summary
 HandlerRegistration addClickHandler(ClickHandler handler)
          Adds a ClickEvent handler.
 void addClickListener(ClickListener listener)
          Deprecated. Use addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead
 HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
          Adds a DoubleClickEvent handler.
 HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
          Adds a MouseDownEvent handler.
 void addMouseListener(MouseListener listener)
          Deprecated. Use addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler), addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler), addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler), addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) and addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) instead
 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)
          Deprecated. Use addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead
 LeafValueEditor<java.lang.String> asEditor()
          Returns the Editor encapsulated by the view object.
 HasHorizontalAlignment.AutoHorizontalAlignmentConstant getAutoHorizontalAlignment()
          Gets the horizontal auto-alignment setting.
 HasDirection.Direction getDirection()
          Deprecated. Use getTextDirection() instead
 DirectionEstimator getDirectionEstimator()
          Returns the DirectionEstimator object.
 HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()
          Gets the horizontal alignment.
 java.lang.String getText()
          Gets this object's text.
 HasDirection.Direction getTextDirection()
          Gets the direction of this object's text.
protected  java.lang.String getTextOrHtml(boolean isHtml)
           
 boolean getWordWrap()
          Gets whether word-wrapping is enabled.
 void removeClickListener(ClickListener listener)
          Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead
 void removeMouseListener(MouseListener listener)
          Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead
 void removeMouseWheelListener(MouseWheelListener listener)
          Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead
 void setAutoHorizontalAlignment(HasHorizontalAlignment.AutoHorizontalAlignmentConstant autoAlignment)
          Sets the horizontal alignment, allowing in addition to the "static" HasHorizontalAlignment.HorizontalAlignmentConstant values, the "automatic" HasHorizontalAlignment.AutoHorizontalAlignmentConstant values that depend on the content direction.
 void setDirection(HasDirection.Direction direction)
          Deprecated. Use setDirectionEstimator(boolean) and / or pass explicit direction to setText(java.lang.String) instead
 void setDirectionEstimator(boolean enabled)
          Toggles on / off direction estimation.
 void setDirectionEstimator(DirectionEstimator directionEstimator)
          Sets the DirectionEstimator object.
 void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)
          Sets the horizontal alignment.
protected  void setHTML(SafeHtml html)
          Sets the label's content to the given safe html.
protected  void setHTML(SafeHtml html, HasDirection.Direction dir)
          Sets the label's content to the given safe html.
 void setText(java.lang.String text)
          Sets the label's content to the given text.
 void setText(java.lang.String text, HasDirection.Direction dir)
          Sets the label's content to the given text, applying the given direction.
protected  void setTextOrHtml(java.lang.String content, boolean isHtml)
          Sets the label's content to the given value (either plain text or HTML).
protected  void setTextOrHtml(java.lang.String content, HasDirection.Direction dir, boolean isHtml)
          Sets the label's content to the given value (either plain text or HTML), applying the given direction.
 void setWordWrap(boolean wrap)
          Sets whether word-wrapping is enabled.
static Label wrap(Element element)
          Creates a Label widget that wraps an existing <div> or <span> element.
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

Label

public Label()
Creates an empty label.


Label

public Label(java.lang.String text)
Creates a label with the specified text.

Parameters:
text - the new label's text

Label

public Label(java.lang.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.

Label

public Label(java.lang.String text,
             boolean wordWrap)
Creates a label with the specified text.

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

Label

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
Method Detail

wrap

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 RootPanel.detachNow(Widget).

Parameters:
element - the element to be wrapped

addClickHandler

public HandlerRegistration addClickHandler(ClickHandler handler)
Description copied from interface: HasClickHandlers
Adds a ClickEvent handler.

Specified by:
addClickHandler in interface HasClickHandlers
Parameters:
handler - the click handler
Returns:
HandlerRegistration used to remove this handler

addClickListener

@Deprecated
public void addClickListener(ClickListener listener)
Deprecated. Use addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead

Description copied from interface: SourcesClickEvents
Adds a listener interface to receive click events.

Specified by:
addClickListener in interface SourcesClickEvents
Parameters:
listener - the listener interface to add

addDoubleClickHandler

public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Description copied from interface: HasDoubleClickHandlers
Adds a DoubleClickEvent handler.

Specified by:
addDoubleClickHandler in interface HasDoubleClickHandlers
Parameters:
handler - the double click handler
Returns:
HandlerRegistration used to remove this handler

addMouseDownHandler

public HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
Description copied from interface: HasMouseDownHandlers
Adds a MouseDownEvent handler.

Specified by:
addMouseDownHandler in interface HasMouseDownHandlers
Parameters:
handler - the mouse down handler
Returns:
HandlerRegistration used to remove this handler

addMouseListener

@Deprecated
public void addMouseListener(MouseListener listener)
Deprecated. Use addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler), addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler), addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler), addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler) and addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) instead

Description copied from interface: SourcesMouseEvents
Adds a listener interface to receive mouse events.

Specified by:
addMouseListener in interface SourcesMouseEvents
Parameters:
listener - the listener interface to add

addMouseMoveHandler

public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
Description copied from interface: HasMouseMoveHandlers
Adds a MouseMoveEvent handler.

Specified by:
addMouseMoveHandler in interface HasMouseMoveHandlers
Parameters:
handler - the mouse move handler
Returns:
HandlerRegistration used to remove this handler

addMouseOutHandler

public HandlerRegistration addMouseOutHandler(MouseOutHandler handler)
Description copied from interface: HasMouseOutHandlers
Adds a MouseOutEvent handler.

Specified by:
addMouseOutHandler in interface HasMouseOutHandlers
Parameters:
handler - the mouse out handler
Returns:
HandlerRegistration used to remove this handler

addMouseOverHandler

public HandlerRegistration addMouseOverHandler(MouseOverHandler handler)
Description copied from interface: HasMouseOverHandlers
Adds a MouseOverEvent handler.

Specified by:
addMouseOverHandler in interface HasMouseOverHandlers
Parameters:
handler - the mouse over handler
Returns:
HandlerRegistration used to remove this handler

addMouseUpHandler

public HandlerRegistration addMouseUpHandler(MouseUpHandler handler)
Description copied from interface: HasMouseUpHandlers
Adds a MouseUpEvent handler.

Specified by:
addMouseUpHandler in interface HasMouseUpHandlers
Parameters:
handler - the mouse up handler
Returns:
HandlerRegistration used to remove this handler

addMouseWheelHandler

public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
Description copied from interface: HasMouseWheelHandlers
Adds a MouseWheelEvent handler.

Specified by:
addMouseWheelHandler in interface HasMouseWheelHandlers
Parameters:
handler - the mouse wheel handler
Returns:
HandlerRegistration used to remove this handler

addMouseWheelListener

@Deprecated
public void addMouseWheelListener(MouseWheelListener listener)
Deprecated. Use addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead


asEditor

public LeafValueEditor<java.lang.String> asEditor()
Description copied from interface: IsEditor
Returns the Editor encapsulated by the view object.

Specified by:
asEditor in interface IsEditor<LeafValueEditor<java.lang.String>>
Returns:
an Editor of type E

getAutoHorizontalAlignment

public HasHorizontalAlignment.AutoHorizontalAlignmentConstant getAutoHorizontalAlignment()
Gets the horizontal auto-alignment setting. This may be one of the auto-alignment values above that depend on content direction (e.g. HasAutoHorizontalAlignment.ALIGN_CONTENT_START), or one of the "static" HasHorizontalAlignment.HorizontalAlignmentConstant alignment values (e.g. HasHorizontalAlignment.ALIGN_LOCALE_START). It may be set by either setAutoHorizontalAlignment or HasHorizontalAlignment#setHorizontalAlignment. The default is null, indicating that no specific horizontal alignment has been set, allowing it to be determined by the usual HTML and CSS mechanisms.

Specified by:
getAutoHorizontalAlignment in interface HasAutoHorizontalAlignment
Returns:
the current automatic horizontal alignment policy.

getDirection

@Deprecated
public HasDirection.Direction getDirection()
Deprecated. Use getTextDirection() instead

Gets the widget element's direction.

Specified by:
getDirection in interface HasDirection
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

getDirectionEstimator

public DirectionEstimator getDirectionEstimator()
Description copied from interface: HasDirectionEstimator
Returns the DirectionEstimator object.

Specified by:
getDirectionEstimator in interface HasDirectionEstimator

getHorizontalAlignment

public HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()
Gets the horizontal alignment.

Specified by:
getHorizontalAlignment in interface HasHorizontalAlignment
Returns:
the current horizontal alignment ( HasHorizontalAlignment.ALIGN_LEFT, HasHorizontalAlignment.ALIGN_CENTER, HasHorizontalAlignment.ALIGN_RIGHT, HasHorizontalAlignment.ALIGN_JUSTIFY, or null).

getText

public java.lang.String getText()
Description copied from interface: HasText
Gets this object's text.

Specified by:
getText in interface HasText
Returns:
the object's text

getTextDirection

public HasDirection.Direction getTextDirection()
Description copied from interface: HasDirectionalText
Gets the direction of this object's text.

Specified by:
getTextDirection in interface HasDirectionalText
Returns:
the direction of this object's text

getWordWrap

public boolean getWordWrap()
Description copied from interface: HasWordWrap
Gets whether word-wrapping is enabled.

Specified by:
getWordWrap in interface HasWordWrap
Returns:
true if word-wrapping is enabled.

removeClickListener

@Deprecated
public void removeClickListener(ClickListener listener)
Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addClickHandler(com.google.gwt.event.dom.client.ClickHandler) instead

Description copied from interface: SourcesClickEvents
Removes a previously added listener interface.

Specified by:
removeClickListener in interface SourcesClickEvents
Parameters:
listener - the listener interface to remove

removeMouseListener

@Deprecated
public void removeMouseListener(MouseListener listener)
Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by an add*Handler method instead

Description copied from interface: SourcesMouseEvents
Removes a previously added listener interface.

Specified by:
removeMouseListener in interface SourcesMouseEvents
Parameters:
listener - the listener interface to remove

removeMouseWheelListener

@Deprecated
public void removeMouseWheelListener(MouseWheelListener listener)
Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler) instead


setAutoHorizontalAlignment

public void setAutoHorizontalAlignment(HasHorizontalAlignment.AutoHorizontalAlignmentConstant autoAlignment)
Sets the horizontal alignment, allowing in addition to the "static" HasHorizontalAlignment.HorizontalAlignmentConstant values, the "automatic" HasHorizontalAlignment.AutoHorizontalAlignmentConstant values that depend on the content direction. Determines the values returned by both HasAutoHorizontalAlignment.getAutoHorizontalAlignment() and HasHorizontalAlignment.getHorizontalAlignment().

For the ALIGN_CONTENT_START and ALIGN_CONTENT_END values, sets the horizontal alignment (including the value of HasHorizontalAlignment#getHorizontalAlignment()) to the start or end edge of the current content's direction, respectively, and continues to automatically update it whenever the content direction changes.

For other values, operates like HasHorizontalAlignment.setHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant).

For null, the horizontal alignment is cleared, allowing it to be determined by the standard HTML mechanisms such as inheritance and CSS rules.

Specified by:
setAutoHorizontalAlignment in interface HasAutoHorizontalAlignment
Parameters:
autoAlignment - the new automatic horizontal alignment policy
See Also:
HasHorizontalAlignment

setDirection

@Deprecated
public void setDirection(HasDirection.Direction direction)
Deprecated. Use setDirectionEstimator(boolean) and / or pass explicit direction to setText(java.lang.String) instead

Sets the widget element's direction.

Specified by:
setDirection in interface HasDirection
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

setDirectionEstimator

public void setDirectionEstimator(boolean enabled)
Toggles on / off direction estimation.

See note at setDirectionEstimator(DirectionEstimator).

Specified by:
setDirectionEstimator in interface HasDirectionEstimator
Parameters:
enabled - Whether to enable direction estimation. If true, sets the DirectionEstimator object to a default DirectionEstimator.

setDirectionEstimator

public void setDirectionEstimator(DirectionEstimator directionEstimator)
Sets the DirectionEstimator object.

Note: if the widget already has non-empty content, this will update its direction according to the new estimator's result. This may cause flicker, and thus should be avoided; DirectionEstimator should be set before the widget has any content.

Specified by:
setDirectionEstimator in interface HasDirectionEstimator
Parameters:
directionEstimator - The {code DirectionEstimator} to be set. null means turning off direction estimation.

setHorizontalAlignment

public void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)
Sets the horizontal alignment.

Use null to clear horizontal alignment, allowing it to be determined by the standard HTML mechanisms such as inheritance and CSS rules.

Note: A subsequent call to setAutoHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment.AutoHorizontalAlignmentConstant) may override the horizontal alignment set by this method.

Note: For null, the horizontal alignment is cleared, allowing it to be determined by the standard HTML mechanisms such as inheritance and CSS rules.

Specified by:
setHorizontalAlignment in interface HasHorizontalAlignment
Parameters:
align - the horizontal alignment ( HasHorizontalAlignment.ALIGN_LEFT, HasHorizontalAlignment.ALIGN_CENTER, HasHorizontalAlignment.ALIGN_RIGHT, HasHorizontalAlignment.ALIGN_JUSTIFY, HasHorizontalAlignment.ALIGN_LOCALE_START, or HasHorizontalAlignment.ALIGN_LOCALE_END).
See Also:
setAutoHorizontalAlignment(com.google.gwt.user.client.ui.HasHorizontalAlignment.AutoHorizontalAlignmentConstant)

setText

public void setText(java.lang.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).

Specified by:
setText in interface HasText
Parameters:
text - the widget's new text

setText

public void setText(java.lang.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:

Specified by:
setText in interface HasDirectionalText
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.

setWordWrap

public void setWordWrap(boolean wrap)
Description copied from interface: HasWordWrap
Sets whether word-wrapping is enabled.

Specified by:
setWordWrap in interface HasWordWrap
Parameters:
wrap - true to enable word-wrapping.

getTextOrHtml

protected java.lang.String getTextOrHtml(boolean isHtml)

setHTML

protected void setHTML(SafeHtml html)
Sets the label's content to the given safe html. See setText(String) for details on potential effects on direction and alignment.

Parameters:
html - the widget's new safe html

setHTML

protected void setHTML(SafeHtml html,
                       HasDirection.Direction dir)
Sets the label's content to the given safe html. See setText(String) for details on potential effects on direction and alignment.

Parameters:
html - the widget's new safe html
dir - the content's direction

setTextOrHtml

protected void setTextOrHtml(java.lang.String content,
                             boolean isHtml)
Sets the label's content to the given value (either plain text or HTML). See setText(String) for details on potential effects on direction and alignment.

Parameters:
content - the widget's new content
isHtml - whether the content is HTML

setTextOrHtml

protected void setTextOrHtml(java.lang.String content,
                             HasDirection.Direction dir,
                             boolean isHtml)
Sets the label's content to the given value (either plain text or HTML), applying the given direction. See setText(String, Direction) for details on potential effects on alignment.

Implementation details:

Parameters:
content - the widget's new content
dir - the content's direction
isHtml - whether the content is HTML

GWT 2.1.0