Package com.google.gwt.user.client.ui
Class Label
- java.lang.Object
-
- com.google.gwt.user.client.ui.UIObject
-
- com.google.gwt.user.client.ui.Widget
-
- com.google.gwt.user.client.ui.LabelBase<java.lang.String>
-
- com.google.gwt.user.client.ui.Label
-
- All Implemented Interfaces:
IsEditor<LeafValueEditor<java.lang.String>>
,HasAllDragAndDropHandlers
,HasAllGestureHandlers
,HasAllMouseHandlers
,HasAllTouchHandlers
,HasClickHandlers
,HasDoubleClickHandlers
,HasDragEndHandlers
,HasDragEnterHandlers
,HasDragHandlers
,HasDragLeaveHandlers
,HasDragOverHandlers
,HasDragStartHandlers
,HasDropHandlers
,HasGestureChangeHandlers
,HasGestureEndHandlers
,HasGestureStartHandlers
,HasMouseDownHandlers
,HasMouseMoveHandlers
,HasMouseOutHandlers
,HasMouseOverHandlers
,HasMouseUpHandlers
,HasMouseWheelHandlers
,HasTouchCancelHandlers
,HasTouchEndHandlers
,HasTouchMoveHandlers
,HasTouchStartHandlers
,HasAttachHandlers
,HasHandlers
,HasDirection
,HasDirectionEstimator
,EventListener
,HasAutoHorizontalAlignment
,HasDirectionalText
,HasHorizontalAlignment
,HasText
,HasVisibility
,HasWordWrap
,IsWidget
,SourcesClickEvents
,SourcesMouseEvents
- Direct Known Subclasses:
HTML
,InlineLabel
public class Label extends LabelBase<java.lang.String> implements HasDirectionalText, HasDirection, HasClickHandlers, HasDoubleClickHandlers, SourcesClickEvents, SourcesMouseEvents, HasAllDragAndDropHandlers, HasAllGestureHandlers, HasAllMouseHandlers, HasAllTouchHandlers, 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.Built-in Bidi Text Support
This widget is capable of automatically adjusting its direction according to its content. This feature is controlled byLabelBase.setDirectionEstimator(boolean)
or passing a DirectionEstimator parameter to the constructor, and is off by default.CSS Style Rules
- .gwt-Label { }
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 Modifier and Type Field Description static DirectionEstimator
DEFAULT_DIRECTION_ESTIMATOR
-
Fields inherited from class com.google.gwt.user.client.ui.LabelBase
directionalTextHelper
-
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSink
-
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
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
Constructors Modifier Constructor Description 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.Label(java.lang.String text, DirectionEstimator directionEstimator)
Creates a label with the specified text and a default direction estimator.
-
Method Summary
-
Methods inherited from class com.google.gwt.user.client.ui.LabelBase
getAutoHorizontalAlignment, getDirectionEstimator, getHorizontalAlignment, getWordWrap, setAutoHorizontalAlignment, setDirectionEstimator, setDirectionEstimator, setHorizontalAlignment, setWordWrap, updateHorizontalAlignment
-
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
-
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, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
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
-
-
-
-
Field Detail
-
DEFAULT_DIRECTION_ESTIMATOR
public static final DirectionEstimator DEFAULT_DIRECTION_ESTIMATOR
-
-
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 textdir
- the text's direction. Note thatDEFAULT
means direction should be inherited from the widget's parent element.
-
Label
public Label(java.lang.String text, DirectionEstimator directionEstimator)
Creates a label with the specified text and a default direction estimator.- Parameters:
text
- the new label's textdirectionEstimator
- A DirectionEstimator object used for automatic direction adjustment. For convenience,DEFAULT_DIRECTION_ESTIMATOR
can be used.
-
Label
public Label(java.lang.String text, boolean wordWrap)
Creates a label with the specified text.- Parameters:
text
- the new label's textwordWrap
-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 callRootPanel.detachNow(Widget)
.- Parameters:
element
- the element to be wrapped
-
addClickHandler
public HandlerRegistration addClickHandler(ClickHandler handler)
Description copied from interface:HasClickHandlers
Adds aClickEvent
handler.- Specified by:
addClickHandler
in interfaceHasClickHandlers
- Parameters:
handler
- the click handler- Returns:
HandlerRegistration
used to remove this handler
-
addClickListener
@Deprecated public void addClickListener(ClickListener listener)
Deprecated.Description copied from interface:SourcesClickEvents
Adds a listener interface to receive click events.- Specified by:
addClickListener
in interfaceSourcesClickEvents
- Parameters:
listener
- the listener interface to add
-
addDoubleClickHandler
public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Description copied from interface:HasDoubleClickHandlers
Adds aDoubleClickEvent
handler.- Specified by:
addDoubleClickHandler
in interfaceHasDoubleClickHandlers
- Parameters:
handler
- the double click handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragEndHandler
public HandlerRegistration addDragEndHandler(DragEndHandler handler)
Description copied from interface:HasDragEndHandlers
Adds aDragEndEvent
handler.- Specified by:
addDragEndHandler
in interfaceHasDragEndHandlers
- Parameters:
handler
- the drag end handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragEnterHandler
public HandlerRegistration addDragEnterHandler(DragEnterHandler handler)
Description copied from interface:HasDragEnterHandlers
Adds aDragEnterEvent
handler.- Specified by:
addDragEnterHandler
in interfaceHasDragEnterHandlers
- Parameters:
handler
- the drag end handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragHandler
public HandlerRegistration addDragHandler(DragHandler handler)
Description copied from interface:HasDragHandlers
Adds aDragEvent
handler.- Specified by:
addDragHandler
in interfaceHasDragHandlers
- Parameters:
handler
- the drag handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragLeaveHandler
public HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler)
Description copied from interface:HasDragLeaveHandlers
Adds aDragLeaveEvent
handler.- Specified by:
addDragLeaveHandler
in interfaceHasDragLeaveHandlers
- Parameters:
handler
- the drag leave handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragOverHandler
public HandlerRegistration addDragOverHandler(DragOverHandler handler)
Description copied from interface:HasDragOverHandlers
Adds aDragOverEvent
handler.- Specified by:
addDragOverHandler
in interfaceHasDragOverHandlers
- Parameters:
handler
- the drag over handler- Returns:
HandlerRegistration
used to remove this handler
-
addDragStartHandler
public HandlerRegistration addDragStartHandler(DragStartHandler handler)
Description copied from interface:HasDragStartHandlers
Adds aDragStartEvent
handler.- Specified by:
addDragStartHandler
in interfaceHasDragStartHandlers
- Parameters:
handler
- the drag start handler- Returns:
HandlerRegistration
used to remove this handler
-
addDropHandler
public HandlerRegistration addDropHandler(DropHandler handler)
Description copied from interface:HasDropHandlers
Adds aDropEvent
handler.- Specified by:
addDropHandler
in interfaceHasDropHandlers
- Parameters:
handler
- the drop handler- Returns:
HandlerRegistration
used to remove this handler
-
addGestureChangeHandler
public HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler)
Description copied from interface:HasGestureChangeHandlers
Adds aGestureChangeEvent
handler.- Specified by:
addGestureChangeHandler
in interfaceHasGestureChangeHandlers
- Parameters:
handler
- the gesture change handler- Returns:
HandlerRegistration
used to remove this handler
-
addGestureEndHandler
public HandlerRegistration addGestureEndHandler(GestureEndHandler handler)
Description copied from interface:HasGestureEndHandlers
Adds aGestureEndEvent
handler.- Specified by:
addGestureEndHandler
in interfaceHasGestureEndHandlers
- Parameters:
handler
- the gesture end handler- Returns:
HandlerRegistration
used to remove this handler
-
addGestureStartHandler
public HandlerRegistration addGestureStartHandler(GestureStartHandler handler)
Description copied from interface:HasGestureStartHandlers
Adds aGestureStartEvent
handler.- Specified by:
addGestureStartHandler
in interfaceHasGestureStartHandlers
- Parameters:
handler
- the gesture start handler- Returns:
HandlerRegistration
used to remove this handler
-
addMouseDownHandler
public HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
Description copied from interface:HasMouseDownHandlers
Adds aMouseDownEvent
handler.- Specified by:
addMouseDownHandler
in interfaceHasMouseDownHandlers
- Parameters:
handler
- the mouse down handler- Returns:
HandlerRegistration
used to remove this handler
-
addMouseListener
@Deprecated public void addMouseListener(MouseListener listener)
Deprecated.UseaddMouseOverHandler(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)
andaddMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler)
insteadDescription copied from interface:SourcesMouseEvents
Adds a listener interface to receive mouse events.- Specified by:
addMouseListener
in interfaceSourcesMouseEvents
- Parameters:
listener
- the listener interface to add
-
addMouseMoveHandler
public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
Description copied from interface:HasMouseMoveHandlers
Adds aMouseMoveEvent
handler.- Specified by:
addMouseMoveHandler
in interfaceHasMouseMoveHandlers
- 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 aMouseOutEvent
handler.- Specified by:
addMouseOutHandler
in interfaceHasMouseOutHandlers
- 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 aMouseOverEvent
handler.- Specified by:
addMouseOverHandler
in interfaceHasMouseOverHandlers
- 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 aMouseUpEvent
handler.- Specified by:
addMouseUpHandler
in interfaceHasMouseUpHandlers
- 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 aMouseWheelEvent
handler.- Specified by:
addMouseWheelHandler
in interfaceHasMouseWheelHandlers
- Parameters:
handler
- the mouse wheel handler- Returns:
HandlerRegistration
used to remove this handler
-
addMouseWheelListener
@Deprecated public void addMouseWheelListener(MouseWheelListener listener)
Deprecated.
-
addTouchCancelHandler
public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler)
Description copied from interface:HasTouchCancelHandlers
Adds aTouchCancelEvent
handler.- Specified by:
addTouchCancelHandler
in interfaceHasTouchCancelHandlers
- Parameters:
handler
- the touch cancel handler- Returns:
HandlerRegistration
used to remove this handler
-
addTouchEndHandler
public HandlerRegistration addTouchEndHandler(TouchEndHandler handler)
Description copied from interface:HasTouchEndHandlers
Adds aTouchEndEvent
handler.- Specified by:
addTouchEndHandler
in interfaceHasTouchEndHandlers
- Parameters:
handler
- the touch end handler- Returns:
HandlerRegistration
used to remove this handler
-
addTouchMoveHandler
public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler)
Description copied from interface:HasTouchMoveHandlers
Adds aTouchMoveEvent
handler.- Specified by:
addTouchMoveHandler
in interfaceHasTouchMoveHandlers
- Parameters:
handler
- the touch move handler- Returns:
HandlerRegistration
used to remove this handler
-
addTouchStartHandler
public HandlerRegistration addTouchStartHandler(TouchStartHandler handler)
Description copied from interface:HasTouchStartHandlers
Adds aTouchStartEvent
handler.- Specified by:
addTouchStartHandler
in interfaceHasTouchStartHandlers
- Parameters:
handler
- the touch start handler- Returns:
HandlerRegistration
used to remove this handler
-
asEditor
public LeafValueEditor<java.lang.String> asEditor()
Description copied from interface:IsEditor
Returns the Editor encapsulated by the view object.- Specified by:
asEditor
in interfaceIsEditor<LeafValueEditor<java.lang.String>>
- Returns:
- an
Editor
of type E
-
getDirection
@Deprecated public HasDirection.Direction getDirection()
Deprecated.UsegetTextDirection()
insteadGets the widget element's direction.- Specified by:
getDirection
in interfaceHasDirection
- Returns:
RTL
if the directionality is right-to-left,LTR
if the directionality is left-to-right, orDEFAULT
if the directionality is not explicitly specified
-
getText
public java.lang.String getText()
Description copied from interface:HasText
Gets this 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 interfaceHasDirectionalText
- Returns:
- the direction of this object's text
-
removeClickListener
@Deprecated public void removeClickListener(ClickListener listener)
Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned byaddClickHandler(com.google.gwt.event.dom.client.ClickHandler)
insteadDescription copied from interface:SourcesClickEvents
Removes a previously added listener interface.- Specified by:
removeClickListener
in interfaceSourcesClickEvents
- Parameters:
listener
- the listener interface to remove
-
removeMouseListener
@Deprecated public void removeMouseListener(MouseListener listener)
Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned by an add*Handler method insteadDescription copied from interface:SourcesMouseEvents
Removes a previously added listener interface.- Specified by:
removeMouseListener
in interfaceSourcesMouseEvents
- Parameters:
listener
- the listener interface to remove
-
removeMouseWheelListener
@Deprecated public void removeMouseWheelListener(MouseWheelListener listener)
Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned byaddMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)
instead
-
setDirection
@Deprecated public void setDirection(HasDirection.Direction direction)
Deprecated.UseLabelBase.setDirectionEstimator(boolean)
and / or pass explicit direction tosetText(java.lang.String)
insteadSets the widget element's direction.- Specified by:
setDirection
in interfaceHasDirection
- Parameters:
direction
-RTL
if the directionality should be set to right-to-left,LTR
if the directionality should be set to left-to-rightDEFAULT
if the directionality should not be explicitly set
-
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 insetText(String, Direction)
.
-
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:
- 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.
- Specified by:
setText
in interfaceHasDirectionalText
- Parameters:
text
- the widget's new textdir
- the text's direction. Note:Direction.DEFAULT
means direction should be inherited from the widget's parent element.
- 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
-
-