Class Button
- All Implemented Interfaces:
AttachNotifier,BlurNotifier<Button>,ClickNotifier<Button>,DetachNotifier,Focusable<Button>,FocusNotifier<Button>,HasAriaLabel,HasElement,HasEnabled,HasSize,HasStyle,HasText,HasTheme,HasPrefix,HasSuffix,HasThemeVariant<ButtonVariant>,HasTooltip,Serializable
- Direct Known Subclasses:
DrawerToggle
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace -
Constructor Summary
ConstructorsConstructorDescriptionButton()Default constructor.Creates a button with an icon inside.Button(Component icon, ComponentEventListener<ClickEvent<Button>> clickListener) Creates a button with an icon and a listener for click events.Creates a button with a text inside.Creates a button with a text and an icon inside.Button(String text, ComponentEventListener<ClickEvent<Button>> clickListener) Creates a button with a text and a listener for click events.Button(String text, Component icon, ComponentEventListener<ClickEvent<Button>> clickListener) Create a button with a text, an icon and a listener for click events. -
Method Summary
Modifier and TypeMethodDescriptionvoidclick()Simulates a click on this button on the server side if it is enabled.voidExecutes a click on this button at the client-side.getIcon()Gets the component that is defined as the icon of this button.booleanGet the state for the auto-focus property of the button.booleanGet if button is set to be disabled on click.booleanGets whether this button's icon is positioned after it's text content or the other way around.protected voidonAttach(AttachEvent attachEvent) Called when the component is attached to a UI.protected voidRemoves the given child components from this component.voidsetAutofocus(boolean autofocus) Set the button to be input focused when the page loads.voidsetDisableOnClick(boolean disableOnClick) Set the button so that it is disabled on click.voidsetEnabled(boolean enabled) Sets the UI object explicitly disabled or enabled.voidSets the given component as the icon of this button.voidsetIconAfterText(boolean iconAfterText) Sets whether this button's icon should be positioned after it's text content or the other way around.voidSets the given string as the text content of this component.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabledMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasSuffix
getSuffixComponent, setSuffixComponentMethods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setWhiteSpaceMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariantsMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipText
-
Constructor Details
-
Button
public Button()Default constructor. Creates an empty button. -
Button
Creates a button with a text inside.- Parameters:
text- the text inside the button- See Also:
-
Button
Creates a button with an icon inside.- Parameters:
icon- the icon inside the button- See Also:
-
Button
Creates a button with a text and an icon inside.Use
setIconAfterText(boolean)to change the order of the text and the icon.- Parameters:
text- the text inside the buttonicon- the icon inside the button- See Also:
-
Button
Creates a button with a text and a listener for click events.- Parameters:
text- the text inside the buttonclickListener- the event listener for click events- See Also:
-
Button
Creates a button with an icon and a listener for click events.- Parameters:
icon- the icon inside the buttonclickListener- the event listener for click events- See Also:
-
Button
public Button(String text, Component icon, ComponentEventListener<ClickEvent<Button>> clickListener) Create a button with a text, an icon and a listener for click events.- Parameters:
text- the text inside the buttonicon- the icon inside the buttonclickListener- the event listener for click events- See Also:
-
-
Method Details
-
setText
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=iconattribute based on whether this button contains only an icon after this operation or not. -
setIcon
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
IconandImage.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=iconattribute based on whether this button contains only an icon after this operation or not.- Parameters:
icon- component to be used as an icon, may benullto only remove the current icon, can't be a text-node
-
getIcon
Gets the component that is defined as the icon of this button.- Returns:
- the icon of this button, or
nullif 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"orslot="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:
trueif this button positions it's icon after it's text content,falseotherwise
-
click
public void click()Simulates a click on this button on the server side if it is enabled. Calling this method executes all registered click listeners on the server side, but does not execute possible client side registered listeners.- See Also:
-
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.- 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
autofocusproperty 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:
trueif button gets disabled on click, elsefalse
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:HasEnabledSets the UI object explicitly disabled or enabled.- Specified by:
setEnabledin interfaceHasEnabled- Parameters:
enabled- iffalsethen explicitly disables the object, iftruethen enables the object so that its state depends on parent
-
remove
Removes the given child components from this component.- Parameters:
components- The components to remove.- Throws:
IllegalArgumentException- if any of the components is not a child of this component.
-
onAttach
Description copied from class:ComponentCalled when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEventis fired for the component.super.onAttachwhen overriding this method.
-