Package com.google.gwt.user.client.ui
Class Label
- All Implemented Interfaces:
IsEditor<LeafValueEditor<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<String>
implements HasDirectionalText, HasDirection, HasClickHandlers, HasDoubleClickHandlers, SourcesClickEvents, SourcesMouseEvents, HasAllDragAndDropHandlers, HasAllGestureHandlers, HasAllMouseHandlers, HasAllTouchHandlers, IsEditor<LeafValueEditor<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 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
ModifierConstructorDescriptionLabel()
Creates an empty label.protected
This constructor may be used by subclasses to explicitly use an existing element.Creates a label with the specified 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. -
Method Summary
Modifier and TypeMethodDescriptionaddClickHandler
(ClickHandler handler) Adds aClickEvent
handler.void
addClickListener
(ClickListener listener) Deprecated.addDoubleClickHandler
(DoubleClickHandler handler) Adds aDoubleClickEvent
handler.addDragEndHandler
(DragEndHandler handler) Adds aDragEndEvent
handler.addDragEnterHandler
(DragEnterHandler handler) Adds aDragEnterEvent
handler.addDragHandler
(DragHandler handler) Adds aDragEvent
handler.addDragLeaveHandler
(DragLeaveHandler handler) Adds aDragLeaveEvent
handler.addDragOverHandler
(DragOverHandler handler) Adds aDragOverEvent
handler.addDragStartHandler
(DragStartHandler handler) Adds aDragStartEvent
handler.addDropHandler
(DropHandler handler) Adds aDropEvent
handler.Adds aGestureChangeEvent
handler.addGestureEndHandler
(GestureEndHandler handler) Adds aGestureEndEvent
handler.Adds aGestureStartEvent
handler.addMouseDownHandler
(MouseDownHandler handler) Adds aMouseDownEvent
handler.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)
insteadaddMouseMoveHandler
(MouseMoveHandler handler) Adds aMouseMoveEvent
handler.addMouseOutHandler
(MouseOutHandler handler) Adds aMouseOutEvent
handler.addMouseOverHandler
(MouseOverHandler handler) Adds aMouseOverEvent
handler.addMouseUpHandler
(MouseUpHandler handler) Adds aMouseUpEvent
handler.addMouseWheelHandler
(MouseWheelHandler handler) Adds aMouseWheelEvent
handler.void
addMouseWheelListener
(MouseWheelListener listener) Deprecated.addTouchCancelHandler
(TouchCancelHandler handler) Adds aTouchCancelEvent
handler.addTouchEndHandler
(TouchEndHandler handler) Adds aTouchEndEvent
handler.addTouchMoveHandler
(TouchMoveHandler handler) Adds aTouchMoveEvent
handler.addTouchStartHandler
(TouchStartHandler handler) Adds aTouchStartEvent
handler.asEditor()
Returns the Editor encapsulated by the view object.Deprecated.UsegetTextDirection()
insteadgetText()
Gets this object's text.Gets the direction of this object's text.void
removeClickListener
(ClickListener listener) Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned byaddClickHandler(com.google.gwt.event.dom.client.ClickHandler)
insteadvoid
removeMouseListener
(MouseListener listener) Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned by an add*Handler method insteadvoid
removeMouseWheelListener
(MouseWheelListener listener) Deprecated.Use theHandlerRegistration.removeHandler()
method on the object returned byaddMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)
insteadvoid
setDirection
(HasDirection.Direction direction) Deprecated.UseLabelBase.setDirectionEstimator(boolean)
and / or pass explicit direction tosetText(java.lang.String)
insteadvoid
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
Creates a Label widget that wraps an existing <div> or <span> element.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 Details
-
DEFAULT_DIRECTION_ESTIMATOR
-
-
Constructor Details
-
Label
public Label()Creates an empty label. -
Label
Creates a label with the specified text.- Parameters:
text
- the new label's text
-
Label
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
Creates a label with the specified text.- Parameters:
text
- the new label's textwordWrap
-false
to disable word wrapping
-
Label
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 Details
-
wrap
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 callWidget.removeFromParent()
.- Parameters:
element
- the element to be wrapped
-
addClickHandler
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.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
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
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
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
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
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
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
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
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
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
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
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
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.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
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
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
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
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
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. -
addTouchCancelHandler
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
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
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
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
Description copied from interface:IsEditor
Returns the Editor encapsulated by the view object.- Specified by:
asEditor
in interfaceIsEditor<LeafValueEditor<String>>
- Returns:
- an
Editor
of type E
-
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
Description copied from interface:HasText
Gets this object's text. -
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.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.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.Use theHandlerRegistration.removeHandler()
method on the object returned byaddMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)
instead -
setDirection
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
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
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
-
addClickHandler(com.google.gwt.event.dom.client.ClickHandler)
instead