public class

HTML

extends Label
implements HasDirectionalHtml HasDirectionalSafeHtml
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.LabelBase<T>
         ↳ com.google.gwt.user.client.ui.Label
           ↳ com.google.gwt.user.client.ui.HTML
Known Direct Subclasses

Class Overview

A widget that can contain arbitrary HTML. This widget uses a <div> element, causing it to be displayed with block layout.

If you only need a simple label (text, but not HTML), then the Label widget is more appropriate, as it disallows the use of HTML, which can lead to potential security issues if not used properly.

Built-in Bidi Text Support

This widget is capable of automatically adjusting its direction according to its content. This feature is controlled by setDirectionEstimator(boolean) or passing a DirectionEstimator parameter to the constructor, and is off by default.

CSS Style Rules

  • .gwt-HTML { }

Example

{@example com.google.gwt.examples.HTMLExample}

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
[Expand]
Inherited Fields
From class com.google.gwt.user.client.ui.Label
From interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasHorizontalAlignment
Public Constructors
HTML()
Creates an empty HTML widget.
HTML(SafeHtml html)
Initializes the widget's HTML from a given SafeHtml object.
HTML(SafeHtml html, HasDirection.Direction dir)
Creates an HTML widget with the specified contents and with the specified direction.
HTML(SafeHtml html, DirectionEstimator directionEstimator)
Creates an HTML widget with the specified HTML contents and specifies a direction estimator.
HTML(String html)
Creates an HTML widget with the specified HTML contents.
HTML(String html, HasDirection.Direction dir)
Creates an HTML widget with the specified HTML contents and with the specified direction.
HTML(String html, boolean wordWrap)
Creates an HTML widget with the specified contents, optionally treating it as HTML, and optionally disabling word wrapping.
Protected Constructors
HTML(Element element)
This constructor may be used by subclasses to explicitly use an existing element.
Public Methods
String getHTML()
Gets this object's contents as HTML.
void setHTML(String html, HasDirection.Direction dir)
Sets the label's content to the given HTML, applying the given direction.
void setHTML(SafeHtml html, HasDirection.Direction dir)
Sets this object's html, also declaring its direction.
void setHTML(SafeHtml html)
Sets this object's contents via known-safe HTML.
void setHTML(String html)
Sets the label's content to the given HTML.
static HTML wrap(Element element)
Creates an HTML widget that wraps an existing <div> or <span> element.
Protected Methods
String getTextOrHtml(boolean isHtml)
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.Label
From class com.google.gwt.user.client.ui.LabelBase
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.editor.client.IsEditor
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.dom.client.HasGestureChangeHandlers
From interface com.google.gwt.event.dom.client.HasGestureEndHandlers
From interface com.google.gwt.event.dom.client.HasGestureStartHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.dom.client.HasTouchCancelHandlers
From interface com.google.gwt.event.dom.client.HasTouchEndHandlers
From interface com.google.gwt.event.dom.client.HasTouchMoveHandlers
From interface com.google.gwt.event.dom.client.HasTouchStartHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.i18n.client.HasDirection
From interface com.google.gwt.i18n.shared.HasDirectionEstimator
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasAutoHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasDirectionalHtml
From interface com.google.gwt.user.client.ui.HasDirectionalSafeHtml
From interface com.google.gwt.user.client.ui.HasDirectionalText
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasHorizontalAlignment
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.HasWordWrap
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents

Public Constructors

public HTML ()

Creates an empty HTML widget.

public HTML (SafeHtml html)

Initializes the widget's HTML from a given SafeHtml object.

Parameters
html the new widget's HTML contents

public HTML (SafeHtml html, HasDirection.Direction dir)

Creates an HTML widget with the specified contents and with the specified direction.

Parameters
html the new widget's SafeHtml contents
dir the content's direction. Note: Direction.DEFAULT means direction should be inherited from the widget's parent element.

public HTML (SafeHtml html, DirectionEstimator directionEstimator)

Creates an HTML widget with the specified HTML contents and specifies a direction estimator.

Parameters
html the new widget's SafeHtml contents
directionEstimator A DirectionEstimator object used for automatic direction adjustment. For convenience, DEFAULT_DIRECTION_ESTIMATOR can be used.

public HTML (String html)

Creates an HTML widget with the specified HTML contents.

Parameters
html the new widget's HTML contents

public HTML (String html, HasDirection.Direction dir)

Creates an HTML widget with the specified HTML contents and with the specified direction.

Parameters
html the new widget's HTML contents
dir the content's direction. Note: Direction.DEFAULT means direction should be inherited from the widget's parent element.

public HTML (String html, boolean wordWrap)

Creates an HTML widget with the specified contents, optionally treating it as HTML, and optionally disabling word wrapping.

Parameters
html the widget's contents
wordWrap false to disable word wrapping

Protected Constructors

protected HTML (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

Public Methods

public String getHTML ()

Gets this object's contents as HTML.

Returns
  • the object's HTML

public void setHTML (String html, HasDirection.Direction dir)

Sets the label's content to the given HTML, applying the given direction. See setText(String, Direction) for details on potential effects on alignment.

Parameters
html the new widget's HTML content
dir the content's direction. Note: Direction.DEFAULT means direction should be inherited from the widget's parent element.

public void setHTML (SafeHtml html, HasDirection.Direction dir)

Sets this object's html, also declaring its direction.

Parameters
html the object's new html
dir the html's direction

public void setHTML (SafeHtml html)

Sets this object's contents via known-safe HTML.

Parameters
html the html to set.

public void setHTML (String html)

Sets the label's content to the given HTML. See setText(String) for details on potential effects on direction and alignment.

Parameters
html the new widget's HTML content

public static HTML wrap (Element element)

Creates an HTML 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 detachNow(Widget).

Parameters
element the element to be wrapped

Protected Methods

protected String getTextOrHtml (boolean isHtml)