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.DebugIdImplEnabledNested classes/interfaces inherited from interface com.google.gwt.i18n.client.HasDirection
HasDirection.DirectionNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant -
Field Summary
FieldsFields inherited from class com.google.gwt.user.client.ui.LabelBase
directionalTextHelperFields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERRORFields inherited from interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
ALIGN_CONTENT_END, ALIGN_CONTENT_STARTFields 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
ConstructorsModifierConstructorDescriptionLabel()Creates an empty label.protectedThis 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 aClickEventhandler.voidaddClickListener(ClickListener listener) Deprecated.addDoubleClickHandler(DoubleClickHandler handler) Adds aDoubleClickEventhandler.addDragEndHandler(DragEndHandler handler) Adds aDragEndEventhandler.addDragEnterHandler(DragEnterHandler handler) Adds aDragEnterEventhandler.addDragHandler(DragHandler handler) Adds aDragEventhandler.addDragLeaveHandler(DragLeaveHandler handler) Adds aDragLeaveEventhandler.addDragOverHandler(DragOverHandler handler) Adds aDragOverEventhandler.addDragStartHandler(DragStartHandler handler) Adds aDragStartEventhandler.addDropHandler(DropHandler handler) Adds aDropEventhandler.Adds aGestureChangeEventhandler.addGestureEndHandler(GestureEndHandler handler) Adds aGestureEndEventhandler.Adds aGestureStartEventhandler.addMouseDownHandler(MouseDownHandler handler) Adds aMouseDownEventhandler.voidaddMouseListener(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 aMouseMoveEventhandler.addMouseOutHandler(MouseOutHandler handler) Adds aMouseOutEventhandler.addMouseOverHandler(MouseOverHandler handler) Adds aMouseOverEventhandler.addMouseUpHandler(MouseUpHandler handler) Adds aMouseUpEventhandler.addMouseWheelHandler(MouseWheelHandler handler) Adds aMouseWheelEventhandler.voidaddMouseWheelListener(MouseWheelListener listener) Deprecated.addTouchCancelHandler(TouchCancelHandler handler) Adds aTouchCancelEventhandler.addTouchEndHandler(TouchEndHandler handler) Adds aTouchEndEventhandler.addTouchMoveHandler(TouchMoveHandler handler) Adds aTouchMoveEventhandler.addTouchStartHandler(TouchStartHandler handler) Adds aTouchStartEventhandler.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.voidremoveClickListener(ClickListener listener) Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned byaddClickHandler(com.google.gwt.event.dom.client.ClickHandler)insteadvoidremoveMouseListener(MouseListener listener) Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned by an add*Handler method insteadvoidremoveMouseWheelListener(MouseWheelListener listener) Deprecated.Use theHandlerRegistration.removeHandler()method on the object returned byaddMouseWheelHandler(com.google.gwt.event.dom.client.MouseWheelHandler)insteadvoidsetDirection(HasDirection.Direction direction) Deprecated.UseLabelBase.setDirectionEstimator(boolean)and / or pass explicit direction tosetText(java.lang.String)insteadvoidSets the label's content to the given text.voidsetText(String text, HasDirection.Direction dir) Sets the label's content to the given text, applying the given direction.static LabelCreates 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, updateHorizontalAlignmentMethods 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, unsinkEventsMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 thatDEFAULTmeans 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-falseto 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:HasClickHandlersAdds aClickEventhandler.- Specified by:
addClickHandlerin interfaceHasClickHandlers- Parameters:
handler- the click handler- Returns:
HandlerRegistrationused to remove this handler
-
addClickListener
Deprecated.Description copied from interface:SourcesClickEventsAdds a listener interface to receive click events.- Specified by:
addClickListenerin interfaceSourcesClickEvents- Parameters:
listener- the listener interface to add
-
addDoubleClickHandler
Description copied from interface:HasDoubleClickHandlersAdds aDoubleClickEventhandler.- Specified by:
addDoubleClickHandlerin interfaceHasDoubleClickHandlers- Parameters:
handler- the double click handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEndHandler
Description copied from interface:HasDragEndHandlersAdds aDragEndEventhandler.- Specified by:
addDragEndHandlerin interfaceHasDragEndHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEnterHandler
Description copied from interface:HasDragEnterHandlersAdds aDragEnterEventhandler.- Specified by:
addDragEnterHandlerin interfaceHasDragEnterHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragHandler
Description copied from interface:HasDragHandlersAdds aDragEventhandler.- Specified by:
addDragHandlerin interfaceHasDragHandlers- Parameters:
handler- the drag handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragLeaveHandler
Description copied from interface:HasDragLeaveHandlersAdds aDragLeaveEventhandler.- Specified by:
addDragLeaveHandlerin interfaceHasDragLeaveHandlers- Parameters:
handler- the drag leave handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragOverHandler
Description copied from interface:HasDragOverHandlersAdds aDragOverEventhandler.- Specified by:
addDragOverHandlerin interfaceHasDragOverHandlers- Parameters:
handler- the drag over handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragStartHandler
Description copied from interface:HasDragStartHandlersAdds aDragStartEventhandler.- Specified by:
addDragStartHandlerin interfaceHasDragStartHandlers- Parameters:
handler- the drag start handler- Returns:
HandlerRegistrationused to remove this handler
-
addDropHandler
Description copied from interface:HasDropHandlersAdds aDropEventhandler.- Specified by:
addDropHandlerin interfaceHasDropHandlers- Parameters:
handler- the drop handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureChangeHandler
Description copied from interface:HasGestureChangeHandlersAdds aGestureChangeEventhandler.- Specified by:
addGestureChangeHandlerin interfaceHasGestureChangeHandlers- Parameters:
handler- the gesture change handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureEndHandler
Description copied from interface:HasGestureEndHandlersAdds aGestureEndEventhandler.- Specified by:
addGestureEndHandlerin interfaceHasGestureEndHandlers- Parameters:
handler- the gesture end handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureStartHandler
Description copied from interface:HasGestureStartHandlersAdds aGestureStartEventhandler.- Specified by:
addGestureStartHandlerin interfaceHasGestureStartHandlers- Parameters:
handler- the gesture start handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseDownHandler
Description copied from interface:HasMouseDownHandlersAdds aMouseDownEventhandler.- Specified by:
addMouseDownHandlerin interfaceHasMouseDownHandlers- Parameters:
handler- the mouse down handler- Returns:
HandlerRegistrationused 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:SourcesMouseEventsAdds a listener interface to receive mouse events.- Specified by:
addMouseListenerin interfaceSourcesMouseEvents- Parameters:
listener- the listener interface to add
-
addMouseMoveHandler
Description copied from interface:HasMouseMoveHandlersAdds aMouseMoveEventhandler.- Specified by:
addMouseMoveHandlerin interfaceHasMouseMoveHandlers- Parameters:
handler- the mouse move handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseOutHandler
Description copied from interface:HasMouseOutHandlersAdds aMouseOutEventhandler.- Specified by:
addMouseOutHandlerin interfaceHasMouseOutHandlers- Parameters:
handler- the mouse out handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseOverHandler
Description copied from interface:HasMouseOverHandlersAdds aMouseOverEventhandler.- Specified by:
addMouseOverHandlerin interfaceHasMouseOverHandlers- Parameters:
handler- the mouse over handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseUpHandler
Description copied from interface:HasMouseUpHandlersAdds aMouseUpEventhandler.- Specified by:
addMouseUpHandlerin interfaceHasMouseUpHandlers- Parameters:
handler- the mouse up handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseWheelHandler
Description copied from interface:HasMouseWheelHandlersAdds aMouseWheelEventhandler.- Specified by:
addMouseWheelHandlerin interfaceHasMouseWheelHandlers- Parameters:
handler- the mouse wheel handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseWheelListener
Deprecated. -
addTouchCancelHandler
Description copied from interface:HasTouchCancelHandlersAdds aTouchCancelEventhandler.- Specified by:
addTouchCancelHandlerin interfaceHasTouchCancelHandlers- Parameters:
handler- the touch cancel handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchEndHandler
Description copied from interface:HasTouchEndHandlersAdds aTouchEndEventhandler.- Specified by:
addTouchEndHandlerin interfaceHasTouchEndHandlers- Parameters:
handler- the touch end handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchMoveHandler
Description copied from interface:HasTouchMoveHandlersAdds aTouchMoveEventhandler.- Specified by:
addTouchMoveHandlerin interfaceHasTouchMoveHandlers- Parameters:
handler- the touch move handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchStartHandler
Description copied from interface:HasTouchStartHandlersAdds aTouchStartEventhandler.- Specified by:
addTouchStartHandlerin interfaceHasTouchStartHandlers- Parameters:
handler- the touch start handler- Returns:
HandlerRegistrationused to remove this handler
-
asEditor
Description copied from interface:IsEditorReturns the Editor encapsulated by the view object.- Specified by:
asEditorin interfaceIsEditor<LeafValueEditor<String>>- Returns:
- an
Editorof type E
-
getDirection
Deprecated.UsegetTextDirection()insteadGets the widget element's direction.- Specified by:
getDirectionin interfaceHasDirection- Returns:
RTLif the directionality is right-to-left,LTRif the directionality is left-to-right, orDEFAULTif the directionality is not explicitly specified
-
getText
Description copied from interface:HasTextGets this object's text. -
getTextDirection
Description copied from interface:HasDirectionalTextGets the direction of this object's text.- Specified by:
getTextDirectionin 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:SourcesClickEventsRemoves a previously added listener interface.- Specified by:
removeClickListenerin 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:SourcesMouseEventsRemoves a previously added listener interface.- Specified by:
removeMouseListenerin 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:
setDirectionin interfaceHasDirection- Parameters:
direction-RTLif the directionality should be set to right-to-left,LTRif the directionality should be set to left-to-rightDEFAULTif 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
directionEstimatoris 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
dirparameter). 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:
setTextin interfaceHasDirectionalText- Parameters:
text- the widget's new textdir- the text's direction. Note:Direction.DEFAULTmeans 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