Class Label

public class Label
extends Widget
implements SourcesClickEvents, SourcesMouseEvents, SourcesMouseWheelEvents, HasHorizontalAlignment, HasText, HasWordWrap

// Superclass of HTML
A widget that contains arbitrary text, not interpreted as HTML.

CSS Style Rules

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);
  }
}

Constructors

Label()Creates an empty label.
Label(String)Creates a label with the specified text.
Label(String, boolean)Creates a label with the specified text.

Methods

addClickListener(ClickListener)Adds a listener interface to receive click events.
addMouseListener(MouseListener)Adds a listener interface to receive mouse events.
addMouseWheelListener(MouseWheelListener)Adds a listener interface to receive mouse events.
getHorizontalAlignment()Gets the horizontal alignment.
getText()Gets this object's text.
getWordWrap()Gets whether word-wrapping is enabled.
onBrowserEvent(Event)
removeClickListener(ClickListener)Removes a previously added listener interface.
removeMouseListener(MouseListener)Removes a previously added listener interface.
removeMouseWheelListener(MouseWheelListener)Removes a previously added listener interface.
setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant)Sets the horizontal alignment.
setText(String)Sets this object's text.
setWordWrap(boolean)Sets whether word-wrapping is enabled.

Constructor Detail

Label

public Label()
Creates an empty label.

Label

public Label(String text)
Creates a label with the specified text.

Parameters

text
the new label's text

Label

public Label(String text, boolean wordWrap)
Creates a label with the specified text.

Parameters

text
the new label's text
wordWrap
false to disable word wrapping

Method Detail

addClickListener

public void addClickListener(ClickListener listener)
Adds a listener interface to receive click events.

Parameters

listener
the listener interface to add

addMouseListener

public void addMouseListener(MouseListener listener)
Adds a listener interface to receive mouse events.

Parameters

listener
the listener interface to add

addMouseWheelListener

public void addMouseWheelListener(MouseWheelListener listener)
Adds a listener interface to receive mouse events.

Parameters

listener
the listener interface to add

getHorizontalAlignment

public HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment()
Gets the horizontal alignment.

Return Value

the current horizontal alignment.

getText

public String getText()
Gets this object's text.

Return Value

the object's text

getWordWrap

public boolean getWordWrap()
Gets whether word-wrapping is enabled.

Return Value

true if word-wrapping is enabled.

onBrowserEvent

public void onBrowserEvent(Event event)

Parameters

event

removeClickListener

public void removeClickListener(ClickListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

removeMouseListener

public void removeMouseListener(MouseListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

removeMouseWheelListener

public void removeMouseWheelListener(MouseWheelListener listener)
Removes a previously added listener interface.

Parameters

listener
the listener interface to remove

setHorizontalAlignment

public void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align)
Sets the horizontal alignment.

Parameters

align
the horizontal alignment ( HasHorizontalAlignment.ALIGN_LEFT, HasHorizontalAlignment.ALIGN_CENTER, or HasHorizontalAlignment.ALIGN_RIGHT).

setText

public void setText(String text)
Sets this object's text.

Parameters

text
the object's new text

setWordWrap

public void setWordWrap(boolean wrap)
Sets whether word-wrapping is enabled.

Parameters

wrap
true to enable word-wrapping.