## com.google.gwt.user.client.ui
Class Anchor

    java.lang.Object
      com.google.gwt.user.client.ui.UIObject
          com.google.gwt.user.client.ui.Widget
              com.google.gwt.user.client.ui.FocusWidget
                  com.google.gwt.user.client.ui.Anchor

All Implemented Interfaces:
  HasAllFocusHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasBlurHandlers, HasClickHandlers, HasFocusHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasHandlers, HasDirection, EventListener, Focusable, HasFocus, HasHorizontalAlignment, HasHTML, HasName, HasText, HasWordWrap, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents

    public class Anchor

extends FocusWidget
implements HasHorizontalAlignment, HasName, HasText, HasHTML, HasWordWrap, HasDirection

A widget that represents a simple <a> element.

### CSS Style Rules

- .gwt-Anchor { }

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.user.client.ui.HasHorizontalAlignment
`HasHorizontalAlignment.HorizontalAlignmentConstant`

Nested classes/interfaces inherited from interface com.google.gwt.i18n.client.HasDirection
`HasDirection.Direction`

Field Summary

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Fields inherited from interface com.google.gwt.user.client.ui.HasHorizontalAlignment
`ALIGN_CENTER, ALIGN_DEFAULT, ALIGN_LEFT, ALIGN_RIGHT`

Constructor Summary
`` | `Anchor()` Creates an empty anchor.
`protected` | `Anchor(Element element)` This constructor may be used by subclasses to explicitly use an existing element.
`` | `Anchor(java.lang.String text)` Creates an anchor for scripting.
`` | `Anchor(java.lang.String text, boolean asHtml)` Creates an anchor for scripting.
`` | `Anchor(java.lang.String text, boolean asHTML, java.lang.String href)` Creates an anchor with its text and href (target URL) specified.
`` | `Anchor(java.lang.String text, boolean asHtml, java.lang.String href, java.lang.String target)` Creates a source anchor (link to URI).
`` | `Anchor(java.lang.String text, java.lang.String href)` Creates an anchor with its text and href (target URL) specified.
`` | `Anchor(java.lang.String text, java.lang.String href, java.lang.String target)` Creates a source anchor with a frame target.

Method Summary
`HasDirection.Direction` | `getDirection()` Gets the directionality of the widget.
`HasHorizontalAlignment.HorizontalAlignmentConstant` | `getHorizontalAlignment()` Gets the horizontal alignment.
`java.lang.String` | `getHref()` Gets the anchor's href (the url to which it links).
`java.lang.String` | `getHTML()` Gets this object's contents as HTML.
`java.lang.String` | `getName()` Gets the widget's name.
`int` | `getTabIndex()` Gets the tab index.
`java.lang.String` | `getTarget()` Gets the anchor's target frame (the frame in which navigation will occur when the link is selected).
`java.lang.String` | `getText()` Gets this object's text.
`boolean` | `getWordWrap()` Gets whether word-wrapping is enabled.
`void` | `setAccessKey(char key)` Sets the widget's 'access key'.
`void` | `setDirection(HasDirection.Direction direction)` Sets the directionality for a widget.
`void` | `setFocus(boolean focused)` Explicitly focus/unfocus this widget.
`void` | `setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)` Sets the horizontal alignment.
`void` | `setHref(java.lang.String href)` Sets the anchor's href (the url to which it links).
`void` | `setHTML(java.lang.String html)` Sets this object's contents via HTML.
`void` | `setName(java.lang.String name)` Sets the widget's name.
`void` | `setTabIndex(int index)` Sets the widget's position in the tab index.
`void` | `setTarget(java.lang.String target)` Sets the anchor's target frame (the frame in which navigation will occur when the link is selected).
`void` | `setText(java.lang.String text)` Sets this object's text.
`void` | `setWordWrap(boolean wrap)` Sets whether word-wrapping is enabled.
`static Anchor` | `wrap(Element element)` Creates an Anchor widget that wraps an existing <a> element.

Methods inherited from class com.google.gwt.user.client.ui.FocusWidget

`addBlurHandler, addClickHandler, addClickListener, addFocusHandler, addFocusListener, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, getFocusImpl, isEnabled, removeClickListener, removeFocusListener, removeKeyboardListener, removeMouseListener, removeMouseWheelListener, setElement, setEnabled`

Methods inherited from class com.google.gwt.user.client.ui.Widget
`addDomHandler, addHandler, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, sinkEvents`

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, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents`

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`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Methods inherited from interface com.google.gwt.event.shared.HasHandlers
`fireEvent`

Constructor Detail

### Anchor

    public Anchor()

  Creates an empty anchor.

### Anchor

    public Anchor(java.lang.String text)

  Creates an anchor for scripting. The anchor's href is set to `javascript:`, based on the expectation that listeners will be added to the anchor.

  Parameters:
    `text` - the anchor's text

### Anchor

    public Anchor(java.lang.String text,
                  boolean asHtml)

  Creates an anchor for scripting. The anchor's href is set to `javascript:`, based on the expectation that listeners will be added to the anchor.

  Parameters:
    `text` - the anchor's text
    `asHtml` - `true` to treat the specified text as html

### Anchor

    public Anchor(java.lang.String text,
                  boolean asHTML,
                  java.lang.String href)

  Creates an anchor with its text and href (target URL) specified.

  Parameters:
    `text` - the anchor's text
    `asHTML` - `true` to treat the specified text as html
    `href` - the url to which it will link

### Anchor

    public Anchor(java.lang.String text,
                  boolean asHtml,
                  java.lang.String href,
                  java.lang.String target)

  Creates a source anchor (link to URI). That is, an anchor with an href attribute specifying the destination URI.

  Parameters:
    `text` - the anchor's text
    `asHtml` - asHTML `true` to treat the specified text as html
    `href` - the url to which it will link
    `target` - the target frame (e.g. "_blank" to open the link in a new window)

### Anchor

    public Anchor(java.lang.String text,
                  java.lang.String href)

  Creates an anchor with its text and href (target URL) specified.

  Parameters:
    `text` - the anchor's text
    `href` - the url to which it will link

### Anchor

    public Anchor(java.lang.String text,
                  java.lang.String href,
                  java.lang.String target)

  Creates a source anchor with a frame target.

  Parameters:
    `text` - the anchor's text
    `href` - the url to which it will link
    `target` - the target frame (e.g. "_blank" to open the link in a new window)

### Anchor

    protected Anchor(Element element)

  This constructor may be used by subclasses to explicitly use an existing element. This element must be an <a> element.

  Parameters:
    `element` - the element to be used

Method Detail

### wrap

    public static Anchor wrap(Element element)

  Creates an Anchor widget that wraps an existing <a> element. This element must already be attached to the document. If the element is removed from the document, you must call `RootPanel.detachNow(Widget)`.

  Parameters:
    `element` - the element to be wrapped

### getDirection

    public HasDirection.Direction getDirection()

  Description copied from interface: `HasDirection`
  Gets the directionality of the widget.

  Specified by:
    `getDirection` in interface `HasDirection`
  Returns:
    `RTL` if the directionality is right-to-left, `LTR` if the directionality is left-to-right, or `DEFAULT` if the directionality is not explicitly specified

### getHorizontalAlignment

    public HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()

  Description copied from interface: `HasHorizontalAlignment`
  Gets the horizontal alignment.

  Specified by:
    `getHorizontalAlignment` in interface `HasHorizontalAlignment`
  Returns:
    the current horizontal alignment.

### getHref

    public java.lang.String getHref()

  Gets the anchor's href (the url to which it links).

  Returns:
    the anchor's href

### getHTML

    public java.lang.String getHTML()

  Description copied from interface: `HasHTML`
  Gets this object's contents as HTML.

  Specified by:
    `getHTML` in interface `HasHTML`
  Returns:
    the object's HTML

### getName

    public java.lang.String getName()

  Description copied from interface: `HasName`
  Gets the widget's name.

  Specified by:
    `getName` in interface `HasName`
  Returns:
    the widget's name

### getTabIndex

    public int getTabIndex()

  Description copied from class: `FocusWidget`
  Gets the tab index.

  Specified by:
    `getTabIndex` in interface `Focusable`
  Overrides:
    `getTabIndex` in class `FocusWidget`
  Returns:
    the tab index

### getTarget

    public java.lang.String getTarget()

  Gets the anchor's target frame (the frame in which navigation will occur when the link is selected).

  Returns:
    the target frame

### getText

    public java.lang.String getText()

  Description copied from interface: `HasText`
  Gets this object's text.

  Specified by:
    `getText` in interface `HasText`
  Returns:
    the object's text

### getWordWrap

    public boolean getWordWrap()

  Description copied from interface: `HasWordWrap`
  Gets whether word-wrapping is enabled.

  Specified by:
    `getWordWrap` in interface `HasWordWrap`
  Returns:
    `true` if word-wrapping is enabled.

### setAccessKey

    public void setAccessKey(char key)

  Description copied from interface: `Focusable`
  Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

  Specified by:
    `setAccessKey` in interface `Focusable`
  Overrides:
    `setAccessKey` in class `FocusWidget`
  Parameters:
    `key` - the widget's access key

### setDirection

    public void setDirection(HasDirection.Direction direction)

  Description copied from interface: `HasDirection`
  Sets the directionality for a widget.

  Specified by:
    `setDirection` in interface `HasDirection`
  Parameters:
    `direction` - `RTL` if the directionality should be set to right-to-left, `LTR` if the directionality should be set to left-to-right `DEFAULT` if the directionality should not be explicitly set

### setFocus

    public void setFocus(boolean focused)

  Description copied from interface: `Focusable`
  Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

  Specified by:
    `setFocus` in interface `Focusable`
  Overrides:
    `setFocus` in class `FocusWidget`
  Parameters:
    `focused` - whether this widget should take focus or release it

### setHorizontalAlignment

    public void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)

  Description copied from interface: `HasHorizontalAlignment`
  Sets the horizontal alignment.

  Specified by:
    `setHorizontalAlignment` in interface `HasHorizontalAlignment`
  Parameters:
    `align` - the horizontal alignment ( `HasHorizontalAlignment.ALIGN_LEFT`, `HasHorizontalAlignment.ALIGN_CENTER`, `HasHorizontalAlignment.ALIGN_RIGHT`), or `HasHorizontalAlignment.ALIGN_DEFAULT`).

### setHref

    public void setHref(java.lang.String href)

  Sets the anchor's href (the url to which it links).

  Parameters:
    `href` - the anchor's href

### setHTML

    public void setHTML(java.lang.String html)

  Description copied from interface: `HasHTML`
  Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using `HasText.setText(String)` whenever possible.

  Specified by:
    `setHTML` in interface `HasHTML`
  Parameters:
    `html` - the object's new HTML

### setName

    public void setName(java.lang.String name)

  Description copied from interface: `HasName`
  Sets the widget's name.

  Specified by:
    `setName` in interface `HasName`
  Parameters:
    `name` - the widget's new name

### setTabIndex

    public void setTabIndex(int index)

  Description copied from interface: `Focusable`
  Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to `-1` will cause this widget to be removed from the tab order.

  Specified by:
    `setTabIndex` in interface `Focusable`
  Overrides:
    `setTabIndex` in class `FocusWidget`
  Parameters:
    `index` - the widget's tab index

### setTarget

    public void setTarget(java.lang.String target)

  Sets the anchor's target frame (the frame in which navigation will occur when the link is selected).

  Parameters:
    `target` - the target frame

### setText

    public void setText(java.lang.String text)

  Description copied from interface: `HasText`
  Sets this object's text.

  Specified by:
    `setText` in interface `HasText`
  Parameters:
    `text` - the object's new text

### setWordWrap

    public void setWordWrap(boolean wrap)

  Description copied from interface: `HasWordWrap`
  Sets whether word-wrapping is enabled.

  Specified by:
    `setWordWrap` in interface `HasWordWrap`
  Parameters:
    `wrap` - `true` to enable word-wrapping.