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 DirectionEstimatorDEFAULT_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.protectedLabel(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 thatDEFAULTmeans 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_ESTIMATORcan 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-falseto 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:HasClickHandlersAdds aClickEventhandler.- Specified by:
addClickHandlerin interfaceHasClickHandlers- Parameters:
handler- the click handler- Returns:
HandlerRegistrationused to remove this handler
-
addClickListener
@Deprecated public void addClickListener(ClickListener listener)
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
public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler)
Description copied from interface:HasDoubleClickHandlersAdds aDoubleClickEventhandler.- Specified by:
addDoubleClickHandlerin interfaceHasDoubleClickHandlers- Parameters:
handler- the double click handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEndHandler
public HandlerRegistration addDragEndHandler(DragEndHandler handler)
Description copied from interface:HasDragEndHandlersAdds aDragEndEventhandler.- Specified by:
addDragEndHandlerin interfaceHasDragEndHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragEnterHandler
public HandlerRegistration addDragEnterHandler(DragEnterHandler handler)
Description copied from interface:HasDragEnterHandlersAdds aDragEnterEventhandler.- Specified by:
addDragEnterHandlerin interfaceHasDragEnterHandlers- Parameters:
handler- the drag end handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragHandler
public HandlerRegistration addDragHandler(DragHandler handler)
Description copied from interface:HasDragHandlersAdds aDragEventhandler.- Specified by:
addDragHandlerin interfaceHasDragHandlers- Parameters:
handler- the drag handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragLeaveHandler
public HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler)
Description copied from interface:HasDragLeaveHandlersAdds aDragLeaveEventhandler.- Specified by:
addDragLeaveHandlerin interfaceHasDragLeaveHandlers- Parameters:
handler- the drag leave handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragOverHandler
public HandlerRegistration addDragOverHandler(DragOverHandler handler)
Description copied from interface:HasDragOverHandlersAdds aDragOverEventhandler.- Specified by:
addDragOverHandlerin interfaceHasDragOverHandlers- Parameters:
handler- the drag over handler- Returns:
HandlerRegistrationused to remove this handler
-
addDragStartHandler
public HandlerRegistration addDragStartHandler(DragStartHandler handler)
Description copied from interface:HasDragStartHandlersAdds aDragStartEventhandler.- Specified by:
addDragStartHandlerin interfaceHasDragStartHandlers- Parameters:
handler- the drag start handler- Returns:
HandlerRegistrationused to remove this handler
-
addDropHandler
public HandlerRegistration addDropHandler(DropHandler handler)
Description copied from interface:HasDropHandlersAdds aDropEventhandler.- Specified by:
addDropHandlerin interfaceHasDropHandlers- Parameters:
handler- the drop handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureChangeHandler
public HandlerRegistration addGestureChangeHandler(GestureChangeHandler handler)
Description copied from interface:HasGestureChangeHandlersAdds aGestureChangeEventhandler.- Specified by:
addGestureChangeHandlerin interfaceHasGestureChangeHandlers- Parameters:
handler- the gesture change handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureEndHandler
public HandlerRegistration addGestureEndHandler(GestureEndHandler handler)
Description copied from interface:HasGestureEndHandlersAdds aGestureEndEventhandler.- Specified by:
addGestureEndHandlerin interfaceHasGestureEndHandlers- Parameters:
handler- the gesture end handler- Returns:
HandlerRegistrationused to remove this handler
-
addGestureStartHandler
public HandlerRegistration addGestureStartHandler(GestureStartHandler handler)
Description copied from interface:HasGestureStartHandlersAdds aGestureStartEventhandler.- Specified by:
addGestureStartHandlerin interfaceHasGestureStartHandlers- Parameters:
handler- the gesture start handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseDownHandler
public HandlerRegistration addMouseDownHandler(MouseDownHandler handler)
Description copied from interface:HasMouseDownHandlersAdds aMouseDownEventhandler.- Specified by:
addMouseDownHandlerin interfaceHasMouseDownHandlers- Parameters:
handler- the mouse down handler- Returns:
HandlerRegistrationused 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:SourcesMouseEventsAdds a listener interface to receive mouse events.- Specified by:
addMouseListenerin interfaceSourcesMouseEvents- Parameters:
listener- the listener interface to add
-
addMouseMoveHandler
public HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler)
Description copied from interface:HasMouseMoveHandlersAdds aMouseMoveEventhandler.- Specified by:
addMouseMoveHandlerin interfaceHasMouseMoveHandlers- Parameters:
handler- the mouse move handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseOutHandler
public HandlerRegistration addMouseOutHandler(MouseOutHandler handler)
Description copied from interface:HasMouseOutHandlersAdds aMouseOutEventhandler.- Specified by:
addMouseOutHandlerin interfaceHasMouseOutHandlers- Parameters:
handler- the mouse out handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseOverHandler
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler)
Description copied from interface:HasMouseOverHandlersAdds aMouseOverEventhandler.- Specified by:
addMouseOverHandlerin interfaceHasMouseOverHandlers- Parameters:
handler- the mouse over handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseUpHandler
public HandlerRegistration addMouseUpHandler(MouseUpHandler handler)
Description copied from interface:HasMouseUpHandlersAdds aMouseUpEventhandler.- Specified by:
addMouseUpHandlerin interfaceHasMouseUpHandlers- Parameters:
handler- the mouse up handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseWheelHandler
public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
Description copied from interface:HasMouseWheelHandlersAdds aMouseWheelEventhandler.- Specified by:
addMouseWheelHandlerin interfaceHasMouseWheelHandlers- Parameters:
handler- the mouse wheel handler- Returns:
HandlerRegistrationused to remove this handler
-
addMouseWheelListener
@Deprecated public void addMouseWheelListener(MouseWheelListener listener)
Deprecated.
-
addTouchCancelHandler
public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler)
Description copied from interface:HasTouchCancelHandlersAdds aTouchCancelEventhandler.- Specified by:
addTouchCancelHandlerin interfaceHasTouchCancelHandlers- Parameters:
handler- the touch cancel handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchEndHandler
public HandlerRegistration addTouchEndHandler(TouchEndHandler handler)
Description copied from interface:HasTouchEndHandlersAdds aTouchEndEventhandler.- Specified by:
addTouchEndHandlerin interfaceHasTouchEndHandlers- Parameters:
handler- the touch end handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchMoveHandler
public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler)
Description copied from interface:HasTouchMoveHandlersAdds aTouchMoveEventhandler.- Specified by:
addTouchMoveHandlerin interfaceHasTouchMoveHandlers- Parameters:
handler- the touch move handler- Returns:
HandlerRegistrationused to remove this handler
-
addTouchStartHandler
public HandlerRegistration addTouchStartHandler(TouchStartHandler handler)
Description copied from interface:HasTouchStartHandlersAdds aTouchStartEventhandler.- Specified by:
addTouchStartHandlerin interfaceHasTouchStartHandlers- Parameters:
handler- the touch start handler- Returns:
HandlerRegistrationused to remove this handler
-
asEditor
public LeafValueEditor<java.lang.String> asEditor()
Description copied from interface:IsEditorReturns the Editor encapsulated by the view object.- Specified by:
asEditorin interfaceIsEditor<LeafValueEditor<java.lang.String>>- Returns:
- an
Editorof type E
-
getDirection
@Deprecated public HasDirection.Direction 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
public java.lang.String getText()
Description copied from interface:HasTextGets this object's text.
-
getTextDirection
public HasDirection.Direction 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 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:SourcesClickEventsRemoves a previously added listener interface.- Specified by:
removeClickListenerin 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:SourcesMouseEventsRemoves a previously added listener interface.- Specified by:
removeMouseListenerin 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:
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
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
directionEstimatoris 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
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
-
-