public class Button extends GeneratedVaadinButton<Button> implements HasSize, HasEnabled
vaadin-button
element.BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
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.
|
Modifier and Type | Method and Description |
---|---|
void |
click()
Simulates a click on this button on the server side.
|
void |
clickInClient()
Executes a click on this button at the client-side.
|
Component |
getIcon()
Gets the component that is defined as the icon of this button.
|
boolean |
isAutofocus()
Get the state for the auto-focus property of the button.
|
boolean |
isDisableOnClick()
Get if button is set to be disabled on click.
|
boolean |
isIconAfterText()
Gets whether this button's icon is positioned after it's text content or
the other way around.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
setAutofocus(boolean autofocus)
Set the button to be input focused when the page loads.
|
void |
setDisableOnClick(boolean disableOnClick)
Set the button so that it is disabled on click.
|
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.
|
addThemeVariants, addToPrefix, addToSuffix, isAutofocusBoolean, isDisabledBoolean, remove, removeAll, removeThemeVariants, setDisabled
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
isEnabled, setEnabled
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addClickListener, addClickShortcut
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
addAttachListener
addDetachListener
public Button()
public Button(String text)
text
- the text inside the buttonsetText(String)
public Button(Component icon)
icon
- the icon inside the buttonsetIcon(Component)
public Button(String text, Component icon)
Use setIconAfterText(boolean)
to change the order of the text
and the icon.
text
- the text inside the buttonicon
- the icon inside the buttonsetText(String)
,
setIcon(Component)
public Button(String text, ComponentEventListener<ClickEvent<Button>> clickListener)
text
- the text inside the buttonclickListener
- the event listener for click eventssetText(String)
,
ClickNotifier.addClickListener(ComponentEventListener)
public Button(Component icon, ComponentEventListener<ClickEvent<Button>> clickListener)
icon
- the icon inside the buttonclickListener
- the event listener for click eventssetIcon(Component)
,
ClickNotifier.addClickListener(ComponentEventListener)
public Button(String text, Component icon, ComponentEventListener<ClickEvent<Button>> clickListener)
text
- the text inside the buttonicon
- the icon inside the buttonclickListener
- the event listener for click eventssetText(String)
,
setIcon(Component)
,
ClickNotifier.addClickListener(ComponentEventListener)
public void setText(String text)
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.
public void setIcon(Component icon)
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.
icon
- component to be used as an icon, may be null
to
only remove the current icon, can't be a text-nodepublic Component getIcon()
null
if the icon is not
setpublic void setIconAfterText(boolean iconAfterText)
At the element-level, this method determines whether to set
slot="prefix"
or slot="suffix"
attribute to the icon.
iconAfterText
- whether the icon should be positioned after the text content
or notpublic boolean isIconAfterText()
true
if this button positions it's icon after it's
text content, false
otherwisepublic void click()
clickInClient()
public void clickInClient()
public void setAutofocus(boolean autofocus)
setAutofocus
in class GeneratedVaadinButton<Button>
autofocus
- the boolean value to setpublic boolean isAutofocus()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
autofocus
property from the buttonpublic void setDisableOnClick(boolean disableOnClick)
Enabling the button needs to happen from the server.
disableOnClick
- true to disable button immediately when clickedpublic boolean isDisableOnClick()
true
if button gets disabled on click, else false
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
Copyright © 2023. All rights reserved.