Class Button

    • Method Detail

      • setText

        public void setText​(String text)
        Sets the given string as the text content of this component.

        This method removes any existing text-content and replaces it with the given text.

        This method also sets or removes this button's theme=icon attribute based on whether this button contains only an icon after this operation or not.

        Specified by:
        setText in interface HasText
        Parameters:
        text - the text content to set, may be null to only remove existing text
      • setIcon

        public void setIcon​(Component icon)
        Sets the given component as the icon of this button.

        Even though you can use almost any component as an icon, some good options are Icon and Image.

        Use setIconAfterText(boolean) to change the icon's position relative to the button's text content.

        This method also sets or removes this button's theme=icon attribute based on whether this button contains only an icon after this operation or not.

        Parameters:
        icon - component to be used as an icon, may be null to only remove the current icon, can't be a text-node
      • getIcon

        public Component getIcon()
        Gets the component that is defined as the icon of this button.
        Returns:
        the icon of this button, or null if the icon is not set
      • setIconAfterText

        public void setIconAfterText​(boolean iconAfterText)
        Sets whether this button's icon should be positioned after it's text content or the other way around.

        At the element-level, this method determines whether to set slot="prefix" or slot="suffix" attribute to the icon.

        Parameters:
        iconAfterText - whether the icon should be positioned after the text content or not
      • isIconAfterText

        public boolean isIconAfterText()
        Gets whether this button's icon is positioned after it's text content or the other way around.
        Returns:
        true if this button positions it's icon after it's text content, false otherwise
      • click

        public void click()
        Simulates a click on this button on the server side. Calling this method executes all registered click listeners on the server side, but does not execute possible client side registered listeners.
        See Also:
        clickInClient()
      • clickInClient

        public void clickInClient()
        Executes a click on this button at the client-side. Calling this method behaves the same as if the user would have clicked on the button.
      • setAutofocus

        public void setAutofocus​(boolean autofocus)
        Set the button to be input focused when the page loads.
        Overrides:
        setAutofocus in class GeneratedVaadinButton<Button>
        Parameters:
        autofocus - the boolean value to set
      • isAutofocus

        public boolean isAutofocus()
        Get the state for the auto-focus property of the button.

        This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.

        Returns:
        the autofocus property from the button
      • setDisableOnClick

        public void setDisableOnClick​(boolean disableOnClick)
        Set the button so that it is disabled on click.

        Enabling the button needs to happen from the server.

        Parameters:
        disableOnClick - true to disable button immediately when clicked
      • isDisableOnClick

        public boolean isDisableOnClick()
        Get if button is set to be disabled on click.
        Returns:
        true if button gets disabled on click, else false
      • onAttach

        protected void onAttach​(AttachEvent attachEvent)
        Description copied from class: Component
        Called when the component is attached to a UI.

        The default implementation does nothing.

        This method is invoked before the AttachEvent is fired for the component.

        Overrides:
        onAttach in class Component
        Parameters:
        attachEvent - the attach event