Class WLabel

public class WLabel extends WInteractWidget
A label for a form field.

The label may contain an image and/or text. It acts like a proxy for giving focus to a WFormWidget. When both an image and text are specified, the image is put to the left of the text.

Usage example:

 WContainerWidget w = new WContainerWidget();
 WLabel label = new WLabel("Favourite Actress: ", w);
 WLineEdit edit = new WLineEdit("Renee Zellweger", w);


The widget corresponds to the HTML <label> tag. When no buddy is set, it is rendered using an HTML <span> or <div> to avoid click event handling misbehavior on Microsoft Internet Explorer.

WLabel is an inline widget.


This widget does not provide styling, and can be styled using inline or external CSS as appropriate. A label's text may be styled via a nested <span> element, and it's image may be styled via a nested <img> element.

  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Description copied from class: WWidget

      Deletes a widget and all contained contents.

      remove in class WInteractWidget
      See Also:
    • getBuddy

      public WFormWidget getBuddy()
      Returns the buddy of this label.

      See Also:
    • setBuddy

      public void setBuddy(WFormWidget buddy)
      Sets the buddy of this label.

      Sets the buddy FormWidget for which this label acts as a proxy.

      See Also:
    • setText

      public void setText(CharSequence text)
      Sets the label text.
    • getText

      public WString getText()
      Returns the label text.
    • setTextFormat

      public boolean setTextFormat(TextFormat format)
      Sets the text format.

      The textFormat controls how the string should be interpreted: either as plain text, which is displayed literally, or as XHTML-markup.

      When changing the textFormat to TextFormat.XHTML, and the current text is literal (not created using WString#tr()), the current text is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is left unchanged, and this method returns false.

      Returns whether the textFormat could be set for the current text.

      The default format is TextFormat.XHTML.

    • getTextFormat

      public TextFormat getTextFormat()
      Returns the text format.

      See Also:
    • setImage

      public void setImage(WImage image, Side side)
      Sets the image.
    • setImage

      public final void setImage(WImage image)
      Sets the image.

      Calls setImage(image, Side.Left)

    • getImage

      public WImage getImage()
      Returns the image.
    • setWordWrap

      public void setWordWrap(boolean wordWrap)
      Configures word wrapping.

      When wordWrap is true, the widget may break lines, creating a multi-line text. When wordWrap is false, the text will displayed on a single line, unless the text contains end-of-lines (for TextFormat.Plain) or <br /> tags or other block-level tags (for TextFormat.XHTML).

      The default value is false.

      See Also:
    • hasWordWrap

      public boolean hasWordWrap()
      Returns whether word wrapping is on.

      See Also:
    • getDomChanges

      protected void getDomChanges(List<DomElement> result, WApplication app)
      Description copied from class: WWebWidget
      Get DOM changes for this widget.

      This is an internal function, and should not be called directly, or be overridden!

      getDomChanges in class WWebWidget
    • propagateSetEnabled

      protected void propagateSetEnabled(boolean enabled)
      Description copied from class: WWidget
      Propagates that a widget was enabled or disabled through children.

      When enabling or disabling a widget, you usually also want to disable contained children. This method is called by setDisabled() to propagate its state to all children.

      You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.

      propagateSetEnabled in class WInteractWidget
    • iterateChildren

      protected void iterateChildren(HandleWidgetMethod method)
      iterateChildren in class WWebWidget
    • updateImage

      protected void updateImage(DomElement element, boolean all, WApplication app, int pos)
    • updateText

      protected void updateText(DomElement element, boolean all, WApplication app, int pos)