com.vaadin.ui.
Class Button
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractField
com.vaadin.ui.Button
All Implemented Interfaces:
Buffered, BufferedValidatable, Property, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.ShortcutNotifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, Field, Serializable, EventListener
Direct Known Subclasses:
- extends AbstractField
- implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier
public class Button
A generic button component.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
class |
Button.ClickEvent
Click event. |
static interface |
Button.ClickListener
Interface for listening for a Button.ClickEvent fired by a
Component . |
static class |
Button.ClickShortcut
A ShortcutListener specifically made to define a keyboard
shortcut that invokes a click on the given button. |
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField |
---|
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent |
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent |
---|
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.Field |
---|
Field.ValueChangeEvent |
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered |
---|
Buffered.SourceException |
Nested classes/interfaces inherited from interface com.vaadin.data.Property |
---|
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer |
Field Summary | |
---|---|
protected Button.ClickShortcut |
clickShortcut
|
static String |
STYLE_LINK
Deprecated. use BaseTheme.BUTTON_LINK instead. |
Constructor Summary | |
---|---|
Button()
Creates a new push button. |
|
Button(String caption)
Creates a new push button. |
|
Button(String caption,
boolean initialState)
Deprecated. use CheckBox instead of Button in "switchmode" |
|
Button(String caption,
Button.ClickListener listener)
Creates a new push button with click listener. |
|
Button(String caption,
Object target,
String methodName)
Creates a new push button with a method listening button clicks. |
|
Button(String caption,
Property dataSource)
Deprecated. use CheckBox instead of Button in "switchmode" |
Method Summary | |
---|---|
void |
addListener(Button.ClickListener listener)
Adds the button click listener. |
void |
addListener(FieldEvents.BlurListener listener)
Adds a BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
void |
addListener(FieldEvents.FocusListener listener)
Adds a FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
boolean |
booleanValue()
Get the boolean value of the button state. |
void |
changeVariables(Object source,
Map<String,Object> variables)
Invoked when the value of a variable has changed. |
void |
click()
Simulates a button click, notifying all server-side listeners. |
protected void |
fireClick()
Fires a click event to all listeners without any event details. |
protected void |
fireClick(MouseEventDetails details)
Fires a click event to all listeners. |
Class |
getType()
The type of the button as a property. |
boolean |
isDisableOnClick()
Determines if a button is automatically disabled when clicked. |
boolean |
isHtmlContentAllowed()
Return HTML rendering setting |
boolean |
isSwitchMode()
Deprecated. the CheckBox component should be used instead of
Button in switch mode |
void |
paintContent(PaintTarget target)
Paints the content of this component. |
void |
removeClickShortcut()
Removes the keyboard shortcut previously set with setClickShortcut(int, int...) . |
void |
removeListener(Button.ClickListener listener)
Removes the button click listener. |
void |
removeListener(FieldEvents.BlurListener listener)
Removes a BlurListener from the Component. |
void |
removeListener(FieldEvents.FocusListener listener)
Removes a FocusListener from the Component. |
void |
setClickShortcut(int keyCode,
int... modifiers)
Makes it possible to invoke a click on this button by pressing the given ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKey s.The shortcut is global (bound to the containing Window). |
void |
setDisableOnClick(boolean disableOnClick)
Determines if a button is automatically disabled when clicked. |
void |
setHtmlContentAllowed(boolean htmlContentAllowed)
Set whether the caption text is rendered as HTML or not. |
void |
setImmediate(boolean immediate)
Sets immediate mode. |
protected void |
setInternalValue(Object newValue)
Sets the internal field value. |
void |
setSwitchMode(boolean switchMode)
Deprecated. the CheckBox component should be used instead of
Button in switch mode |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.vaadin.ui.Field |
---|
getDescription, setCaption, setDescription |
Field Detail |
---|
STYLE_LINK
@Deprecated
public static final String STYLE_LINK
- See Also:
- Constant Field Values
Deprecated. use BaseTheme.BUTTON_LINK
instead.
Button style with no decorations. Looks like a link, acts like a button
clickShortcut
protected Button.ClickShortcut clickShortcut
Constructor Detail |
---|
Button
public Button()
Creates a new push button. The value of the push button is false and it is immediate by default.
Button
public Button(String caption)
- Parameters:
caption
- the Button caption.
Creates a new push button. The value of the push button is false and it is immediate by default.
Button
public Button(String caption,
Button.ClickListener listener)
- Parameters:
caption
- the Button caption.listener
- the Button click listener.
Creates a new push button with click listener.
Button
public Button(String caption,
Object target,
String methodName)
- Parameters:
caption
- the Button caption.target
- the Object having the method for listening button clicks.methodName
- the name of the method in target object, that receives button click events.
Creates a new push button with a method listening button clicks. Using
this method is discouraged because it cannot be checked during
compilation. Use
Button(String, com.vaadin.ui.Button.ClickListener)
instead. The
method must have either no parameters, or only one parameter of
Button.ClickEvent type.
Button
@Deprecated
public Button(String caption,
boolean initialState)
- Parameters:
state
- the Initial state of the switch-button.initialState
-
Deprecated. use CheckBox
instead of Button in "switchmode"
Creates a new switch button with initial value.
Button
@Deprecated
public Button(String caption,
Property dataSource)
- Parameters:
state
- the Initial state of the switch-button.dataSource
-
Deprecated. use CheckBox
instead of Button in "switchmode"
Creates a new switch button that is connected to a boolean property.
Method Detail |
---|
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractField
- Parameters:
event
- the PaintEvent.- Throws:
IOException
- if the writing failed due to input/output error.PaintException
- if the paint operation failed.
Paints the content of this component.
changeVariables
public void changeVariables(Object source,
Map<String,Object> variables)
- Specified by:
changeVariables
in interfaceVariableOwner
- Overrides:
changeVariables
in classAbstractField
- Parameters:
source
-variables
-
Invoked when the value of a variable has changed. Button listeners are notified if the button is clicked.
isSwitchMode
@Deprecated
public boolean isSwitchMode()
- Returns:
true
if it is in Switch Mode, otherwisefalse
.
Deprecated. the CheckBox
component should be used instead of
Button in switch mode
Checks if it is switchMode.
setSwitchMode
@Deprecated
public void setSwitchMode(boolean switchMode)
- Parameters:
switchMode
- The switchMode to set.
Deprecated. the CheckBox
component should be used instead of
Button in switch mode
Sets the switchMode.
booleanValue
public boolean booleanValue()
- Returns:
- True iff the button is pressed down or checked.
Get the boolean value of the button state.
setImmediate
public void setImmediate(boolean immediate)
- Overrides:
setImmediate
in classAbstractComponent
- Parameters:
immediate
- the boolean value specifying if the component should be in the immediate mode after the call.- See Also:
AbstractComponent.setImmediate(boolean)
Sets immediate mode. Push buttons can not be set in non-immediate mode.
getType
public Class getType()
- Specified by:
getType
in interfaceProperty
- Specified by:
getType
in classAbstractField
- Returns:
- type of the Property
- See Also:
Property.getType()
The type of the button as a property.
addListener
public void addListener(Button.ClickListener listener)
- Parameters:
listener
- the Listener to be added.
Adds the button click listener.
removeListener
public void removeListener(Button.ClickListener listener)
- Parameters:
listener
- the Listener to be removed.
Removes the button click listener.
click
public void click()
Simulates a button click, notifying all server-side listeners. No action is taken is the button is disabled.
fireClick
protected void fireClick()
Fires a click event to all listeners without any event details.
In subclasses, override fireClick(MouseEventDetails)
instead of
this method.
fireClick
protected void fireClick(MouseEventDetails details)
- Parameters:
details
- MouseEventDetails from which keyboard modifiers and other information about the mouse click can be obtained. If the button was clicked by a keyboard event, some of the fields may be empty/undefined.
Fires a click event to all listeners.
setInternalValue
protected void setInternalValue(Object newValue)
- Overrides:
setInternalValue
in classAbstractField
- Parameters:
newValue
- the new value to be set.
Description copied from class: AbstractField
Sets the internal field value. This is purely used by AbstractField to change the internal Field value. It does not trigger valuechange events. It can be overridden by the inheriting classes to update all dependent variables.
addListener
public void addListener(FieldEvents.BlurListener listener)
- Specified by:
addListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Adds a BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.
removeListener
public void removeListener(FieldEvents.BlurListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener
from the Component.
addListener
public void addListener(FieldEvents.FocusListener listener)
- Specified by:
addListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Adds a FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.
removeListener
public void removeListener(FieldEvents.FocusListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener
from the Component.
setClickShortcut
public void setClickShortcut(int keyCode,
int... modifiers)
- Parameters:
keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut, null for none
Makes it possible to invoke a click on this button by pressing the given
ShortcutAction.KeyCode
and (optional) ShortcutAction.ModifierKey
s.
The shortcut is global (bound to the containing Window).
removeClickShortcut
public void removeClickShortcut()
Removes the keyboard shortcut previously set with
setClickShortcut(int, int...)
.
isDisableOnClick
public boolean isDisableOnClick()
- Returns:
- true if the button is disabled when clicked, false otherwise
Determines if a button is automatically disabled when clicked. See
setDisableOnClick(boolean)
for details.
setDisableOnClick
public void setDisableOnClick(boolean disableOnClick)
- Parameters:
disableOnClick
- true to disable button when it is clicked, false otherwise
Determines if a button is automatically disabled when clicked. If this is set to true the button will be automatically disabled when clicked, typically to prevent (accidental) extra clicks on a button.
Note that this is only used when the click comes from the user, not when
calling click()
.
Also note that click shortcuts are not supported with this feature in Vaadin 6.x.
setHtmlContentAllowed
public void setHtmlContentAllowed(boolean htmlContentAllowed)
- Parameters:
htmlContentAllowed
-true
if caption is rendered as HTML,false
otherwise
Set whether the caption text is rendered as HTML or not. You might need to retheme button to allow higher content than the original text style. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text.
isHtmlContentAllowed
public boolean isHtmlContentAllowed()
- Returns:
true
if the caption text is to be rendered as HTML,false
otherwise
Return HTML rendering setting