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);
     label.setBuddy(edit);
    
     

    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.

    CSS

    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.

    • Method Detail

      • setText

        public void setText​(java.lang.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.

      • setImage

        public void setImage​(WImage image,
                             Side side)
        Sets the image.
      • 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()
      • getDomChanges

        protected void getDomChanges​(java.util.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!

        Overrides:
        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.

        Overrides:
        propagateSetEnabled in class WInteractWidget