Class WAbstractToggleButton

Direct Known Subclasses:
WCheckBox, WRadioButton

public abstract class WAbstractToggleButton extends WFormWidget
An abstract base class for radio buttons and check boxes.

A toggle button provides a button with a boolean state (checked or unchecked), and a text label.

To act on a change of the state, either connect a slot to the WFormWidget.changed() signal, or connect a slot to the checked() or unChecked() signals.

The current state (checked or unchecked) may be inspected using the isChecked() method.

  • Constructor Details

    • WAbstractToggleButton

      protected WAbstractToggleButton(WContainerWidget parentContainer)
      Creates an unchecked toggle button without label.
    • WAbstractToggleButton

      protected WAbstractToggleButton()
      Creates an unchecked toggle button without label.

      Calls this((WContainerWidget)null)

    • WAbstractToggleButton

      protected WAbstractToggleButton(CharSequence text, WContainerWidget parentContainer)
      Creates an unchecked toggle button with given text label.

      The text label is rendered to the right side of the button.

    • WAbstractToggleButton

      protected WAbstractToggleButton(CharSequence text)
      Creates an unchecked toggle button with given text label.

      Calls this(text, (WContainerWidget)null)

  • Method Details

    • remove

      public void remove()
      Destructor.
      Overrides:
      remove in class WFormWidget
      See Also:
    • setText

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

      The label is rendered to the right of the button.

    • getText

      public WString getText()
      Returns the label text.

      See Also:
    • 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.Plain.

    • getTextFormat

      public TextFormat getTextFormat()
      Returns the text format.

      See Also:
    • isChecked

      public boolean isChecked()
      Returns the button state.

      See Also:
    • setChecked

      public void setChecked(boolean how)
      Sets the button state.

      This method does not emit one of the checked() or unChecked() signals.

      See Also:
    • setChecked

      public void setChecked()
      Checks the button.

      Does not emit the checked() signal.

      See Also:
    • setUnChecked

      public void setUnChecked()
      Unchecks the button.

      Does not emit the unChecked() signal.

      See Also:
    • getValueText

      public String getValueText()
      Returns the current value.

      Returns "yes" when checked, "maybe" when partially checked, and "no" when unchecked.

      Specified by:
      getValueText in class WFormWidget
    • setValueText

      public void setValueText(String text)
      Sets the current value.

      This interprets text values of "yes", "maybe" or "no".

      Specified by:
      setValueText in class WFormWidget
    • checked

      public EventSignal checked()
      Signal emitted when the button gets checked.

      This signal is emitted when the user checks the button.

      You can use the WFormWidget.changed() signal to react when the user makes any change to the button state.

    • unChecked

      public EventSignal unChecked()
      Signal emitted when the button gets un-checked.

      This signal is emitted when the user unchecks the button.

      You can use the WFormWidget.changed() signal to react when the user makes any change to the button state.

      Remark: This signal is not emitted for WRadioButton. In this case a button can only be unchecked because another button is checked. The browser will only generate an event for the button which was checked. Since EventSignal mirrors browser events, JWt will also not emit this signal. The function WButtonGroup.checkedChanged() might be easier to use in this case.

    • refresh

      public void refresh()
      Description copied from class: WWidget
      Refresh the widget.

      The refresh method is invoked when the locale is changed using WApplication#setLocale() or when the user hit the refresh button.

      The widget must actualize its contents in response.

      Note: This does not rerender the widget! Calling refresh() usually does not have any effect (unless you've reimplemented refresh() to attach to it an effect).

      Overrides:
      refresh in class WFormWidget
    • 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:
    • isWordWrap

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

      See Also:
    • setFormData

      protected void setFormData(WObject.FormData formData)
      Overrides:
      setFormData in class WObject