com.vaadin.flow.component.button.
Class Button
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.button.GeneratedVaadinButton<Button>
-
- com.vaadin.flow.component.button.Button
-
All Implemented Interfaces:
AttachNotifier, BlurNotifier<Button>, ClickNotifier<Button>, DetachNotifier, Focusable<Button>, FocusNotifier<Button>, HasElement, HasEnabled, HasSize, HasStyle, HasText, Serializable
public class Button extends GeneratedVaadinButton<Button> implements HasSize, HasEnabled
Server-side component for the
vaadin-button
element.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>
-
-
Constructor Summary
Constructors Constructor and Description Button()
Default constructor.
Button(Component icon)
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.
Button(String text)
Creates a button with a text inside.
Button(String text, Component icon)
Creates a button with a text and an icon inside.
Button(String text, Component icon, ComponentEventListener<ClickEvent<Button>> clickListener)
Create a button with a text, an icon and a listener for click events.
Button(String text, ComponentEventListener<ClickEvent<Button>> clickListener)
Creates a button with a text and a listener for click events.
-
Method Summary
All Methods Modifier and Type Method and Description void
click()
Executes a click on this button at the client-side.
Component
getIcon()
Gets the component that is defined as the icon of this button.
String
getText()
Gets the text content of this button.
boolean
isAutofocus()
Get the state for the auto-focus property of the button.
boolean
isIconAfterText()
Gets whether this button's icon is positioned after it's text content or the other way around.
void
setAutofocus(boolean autofocus)
Set the button to be input focused when the page loads.
void
setIcon(Component icon)
Sets the given component as the icon of this button.
void
setIconAfterText(boolean iconAfterText)
Sets whether this button's icon should be positioned after it's text content or the other way around.
void
setText(String text)
Sets the given string as the text content of this component.
-
Methods inherited from class com.vaadin.flow.component.button.GeneratedVaadinButton
addToPrefix, addToSuffix, isAutofocusBoolean, isDisabledBoolean, remove, removeAll, setDisabled
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getWidth, setHeight, setSizeFull, setSizeUndefined, setWidth
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener
-
Methods inherited from interface com.vaadin.flow.component.Focusable
blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
Button
public Button()
Default constructor. Creates an empty button.
-
Button
public Button(String text)
Creates a button with a text inside.
Parameters:
text
- the text inside the buttonSee Also:
-
Button
public Button(Component icon)
Creates a button with an icon inside.
Parameters:
icon
- the icon inside the buttonSee Also:
-
Button
public Button(String text, Component icon)
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 buttonSee Also:
-
Button
public Button(String text, ComponentEventListener<ClickEvent<Button>> clickListener)
Creates a button with a text and a listener for click events.
Parameters:
text
- the text inside the buttonclickListener
- the event listener for click eventsSee Also:
setText(String)
,ClickNotifier.addClickListener(ComponentEventListener)
-
Button
public Button(Component icon, ComponentEventListener<ClickEvent<Button>> clickListener)
Creates a button with an icon and a listener for click events.
Parameters:
icon
- the icon inside the buttonclickListener
- the event listener for click eventsSee Also:
setIcon(Component)
,ClickNotifier.addClickListener(ComponentEventListener)
-
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 eventsSee Also:
setText(String)
,setIcon(Component)
,ClickNotifier.addClickListener(ComponentEventListener)
-
-
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.
If an icon has been set, the text will be wrapped in a
span
-element.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.
-
getText
public String getText()
Gets the text content of this button.
If an icon has been set for this button, this method returns the text content wrapped in a
span
-element. Otherwise this method returns the text in this button without considering the text in any child components or elements.
-
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
andImage
.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 and wraps it's possible text-content in aspan
-element for better theming support.Parameters:
icon
- component to be used as an icon, may benull
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.
This method reorders possibly existing icon and text content if needed and also affects icon and text that are set afterwards.
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()
Executes a click on this button at the client-side. Calling this method behaves exactly 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 classGeneratedVaadinButton<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
-
-