Class WPushButton


  • public class WPushButton
    extends WFormWidget
    A widget that represents a push button.

    To act on a button click, connect a slot to the WInteractWidget.clicked() signal.

    WPushButton is an inline widget.

    CSS

    The widget corresponds to the HTML <button> tag (with some exceptions in the bootstrap theme).

    • Method Detail

      • setDefault

        public void setDefault​(boolean enabled)
        Sets the default property.

        This has only a functional meaning for a button in a dialog footer, as it becomes associated with pressing 'enter' in the dialog.

        A default button may be rendered in a different style, depending on the theme.

      • setCheckable

        public void setCheckable​(boolean checkable)
        Sets whether the button is checkable.

        A checkable button can be checked and unchecked, and clicking will toggle between these two states.

        See Also:
        setChecked(boolean checked)
      • isChecked

        public boolean isChecked()
        Returns the button state.

        See Also:
        setChecked()
      • setText

        public boolean setText​(java.lang.CharSequence text)
        Sets the button text.

        The default text format is TextFormat.Plain.

        When the current text format is TextFormat.XHTML, and text is literal (not created using WString#tr()), it is parsed using an XML parser which discards malicious tags and attributes silently. When the parser encounters an XML parse error, the textFormat is changed to TextFormat.Plain. If text is not a literal, the same parser is applied only when the text is resolved.

        Returns whether the text could be set using the current textFormat. A return value of false indicates that the text format was changed in order to be able to accept the new text.

        See Also:
        setTextFormat(TextFormat textFormat)
      • setTextFormat

        public boolean setTextFormat​(TextFormat textFormat)
        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.

      • setIcon

        public void setIcon​(WLink link)
        Sets an icon.

        The icon is placed to the left of the text.

      • setLink

        public void setLink​(WLink link)
        Sets a destination link.

        This method can be used to make the button behave like a WAnchor (or conversely, an anchor look like a button) and redirect to another URL when clicked.

        The link may be to a URL, a resource, or an internal path.

        By default, a button does not link to an URL and you should listen to the WInteractWidget.clicked() signal to react to a click event.

        Warning: In Bootstrap theme, you should set a link before it's rendered since it commit's the button to be rendered as an anchor. (see also http://redmine.emweb.be/issues/1802).

      • getValueText

        public java.lang.String getValueText()
        Returns the current value.

        Returns an empty string, since a button has no value.

        Specified by:
        getValueText in class WFormWidget
      • setValueText

        public void setValueText​(java.lang.String value)
        Sets the current value.

        Has no effect, since a button has not value.

        Specified by:
        setValueText in class WFormWidget
      • setMenu

        public void setMenu​(WPopupMenu popupMenu)
        Links a popup menu to the button.

        When the button is clicked, the linked popup menu is shown.

      • 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
      • isSetFirstFocus

        public boolean isSetFirstFocus()
        Description copied from class: WWidget
        Set focus on the widget's first descendant.

        Set focus on the widget itself, or on a first descendant which can receive focus.

        Returns whether focus could be set.

        Overrides:
        isSetFirstFocus in class WWebWidget
      • 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 WFormWidget
      • enableAjax

        protected void enableAjax()
        Description copied from class: WWidget
        Progresses to an Ajax-enabled widget.

        This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

        You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

        Overrides:
        enableAjax in class WFormWidget
        See Also:
        WApplication.enableAjax()