com.vaadin.ui
Class Button

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.Button
All Implemented Interfaces:
Action.ShortcutNotifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, ClientConnector, Sizeable, com.vaadin.shared.Connector, Component, Component.Focusable, java.io.Serializable
Direct Known Subclasses:
NativeButton

public class Button
extends AbstractComponent
implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, Component.Focusable, Action.ShortcutNotifier

A generic button component.

Since:
3.0
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
static 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 interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Field Summary
protected  Button.ClickShortcut clickShortcut
           
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
Button()
          Creates a new push button.
Button(Resource icon)
          Creates a new push button with the given icon.
Button(java.lang.String caption)
          Creates a new push button with the given caption.
Button(java.lang.String caption, Button.ClickListener listener)
          Creates a new push button with a click listener.
Button(java.lang.String caption, Resource icon)
          Creates a new push button with the given caption and icon.
 
Method Summary
 void addBlurListener(FieldEvents.BlurListener listener)
          Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.
 void addClickListener(Button.ClickListener listener)
          Adds the button click listener.
 void addFocusListener(FieldEvents.FocusListener listener)
          Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.
 void addListener(Button.ClickListener listener)
          Deprecated. As of 7.0, replaced by addClickListener(ClickListener)
 void addListener(FieldEvents.BlurListener listener)
          Deprecated. As of 7.0, replaced by #addBlurListener(BlurListener)
 void addListener(FieldEvents.FocusListener listener)
          Deprecated. As of 7.0, replaced by #addFocusListener(FocusListener)
 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(com.vaadin.shared.MouseEventDetails details)
          Fires a click event to all listeners.
 void focus()
          Sets the focus for this component if the component is Focusable.
 java.lang.String getIconAlternateText()
          Returns the icon's alt text.
protected  com.vaadin.shared.ui.button.ButtonState getState()
          Returns the shared state bean with information to be sent from the server to the client.
protected  com.vaadin.shared.ui.button.ButtonState getState(boolean markAsDirty)
          Returns the shared state for this connector.
 int getTabIndex()
          Gets the tabulator index of the Focusable component.
 boolean isDisableOnClick()
          Determines if a button is automatically disabled when clicked.
 boolean isHtmlContentAllowed()
          Return HTML rendering setting
 void removeBlurListener(FieldEvents.BlurListener listener)
          Removes a BlurListener from the Component.
 void removeClickListener(Button.ClickListener listener)
          Removes the button click listener.
 void removeClickShortcut()
          Removes the keyboard shortcut previously set with setClickShortcut(int, int...).
 void removeFocusListener(FieldEvents.FocusListener listener)
          Removes a FocusListener from the Component.
 void removeListener(Button.ClickListener listener)
          Deprecated. As of 7.0, replaced by removeClickListener(ClickListener)
 void removeListener(FieldEvents.BlurListener listener)
          Deprecated. As of 7.0, replaced by #removeBlurListener(BlurListener)
 void removeListener(FieldEvents.FocusListener listener)
          Deprecated. As of 7.0, replaced by #removeFocusListener(FocusListener)
 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.ModifierKeys.
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 setIcon(Resource icon, java.lang.String iconAltText)
          Sets the component's icon and alt text.
 void setIconAlternateText(java.lang.String iconAltText)
           
 void setTabIndex(int tabIndex)
          Sets the tabulator index of the Focusable component.
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hasListeners, isAttached, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
 
Methods inherited from interface com.vaadin.event.Action.ShortcutNotifier
addShortcutListener, removeShortcutListener
 

Field Detail

clickShortcut

protected Button.ClickShortcut clickShortcut
Constructor Detail

Button

public Button()
Creates a new push button.


Button

public Button(java.lang.String caption)
Creates a new push button with the given caption.

Parameters:
caption - the Button caption.

Button

public Button(Resource icon)
Creates a new push button with the given icon.

Parameters:
icon - the icon

Button

public Button(java.lang.String caption,
              Resource icon)
Creates a new push button with the given caption and icon.

Parameters:
caption - the caption
icon - the icon

Button

public Button(java.lang.String caption,
              Button.ClickListener listener)
Creates a new push button with a click listener.

Parameters:
caption - the Button caption.
listener - the Button click listener.
Method Detail

addClickListener

public void addClickListener(Button.ClickListener listener)
Adds the button click listener.

Parameters:
listener - the Listener to be added.

addListener

@Deprecated
public void addListener(Button.ClickListener listener)
Deprecated. As of 7.0, replaced by addClickListener(ClickListener)


removeClickListener

public void removeClickListener(Button.ClickListener listener)
Removes the button click listener.

Parameters:
listener - the Listener to be removed.

removeListener

@Deprecated
public void removeListener(Button.ClickListener listener)
Deprecated. As of 7.0, replaced by removeClickListener(ClickListener)


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(com.vaadin.shared.MouseEventDetails details)
Fires a click event to all listeners.

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.

addBlurListener

public void addBlurListener(FieldEvents.BlurListener listener)
Description copied from interface: FieldEvents.BlurNotifier
Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.

Specified by:
addBlurListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurListener

addListener

@Deprecated
public void addListener(FieldEvents.BlurListener listener)
Deprecated. As of 7.0, replaced by #addBlurListener(BlurListener)

Specified by:
addListener in interface FieldEvents.BlurNotifier

removeBlurListener

public void removeBlurListener(FieldEvents.BlurListener listener)
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener from the Component.

Specified by:
removeBlurListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurListener

removeListener

@Deprecated
public void removeListener(FieldEvents.BlurListener listener)
Deprecated. As of 7.0, replaced by #removeBlurListener(BlurListener)

Specified by:
removeListener in interface FieldEvents.BlurNotifier

addFocusListener

public void addFocusListener(FieldEvents.FocusListener listener)
Description copied from interface: FieldEvents.FocusNotifier
Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.

Specified by:
addFocusListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusListener

addListener

@Deprecated
public void addListener(FieldEvents.FocusListener listener)
Deprecated. As of 7.0, replaced by #addFocusListener(FocusListener)

Specified by:
addListener in interface FieldEvents.FocusNotifier

removeFocusListener

public void removeFocusListener(FieldEvents.FocusListener listener)
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener from the Component.

Specified by:
removeFocusListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusListener

removeListener

@Deprecated
public void removeListener(FieldEvents.FocusListener listener)
Deprecated. As of 7.0, replaced by #removeFocusListener(FocusListener)

Specified by:
removeListener in interface FieldEvents.FocusNotifier

setClickShortcut

public 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.ModifierKeys.
The shortcut is global (bound to the containing Window).

Parameters:
keyCode - the keycode for invoking the shortcut
modifiers - the (optional) modifiers for invoking the shortcut, null for none

removeClickShortcut

public void removeClickShortcut()
Removes the keyboard shortcut previously set with setClickShortcut(int, int...).


isDisableOnClick

public boolean isDisableOnClick()
Determines if a button is automatically disabled when clicked. See setDisableOnClick(boolean) for details.

Returns:
true if the button is disabled when clicked, false otherwise

setDisableOnClick

public void setDisableOnClick(boolean disableOnClick)
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().

Parameters:
disableOnClick - true to disable button when it is clicked, false otherwise

getTabIndex

public int getTabIndex()
Description copied from interface: Component.Focusable
Gets the tabulator index of the Focusable component.

Specified by:
getTabIndex in interface Component.Focusable
Returns:
tab index set for the Focusable component
See Also:
Component.Focusable.setTabIndex(int)

setTabIndex

public void setTabIndex(int tabIndex)
Description copied from interface: Component.Focusable
Sets the tabulator index of the Focusable component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.
 Form loginBox = new Form();
 loginBox.setCaption("Login");
 layout.addComponent(loginBox);
 
 // Create the first field which will be focused
 TextField username = new TextField("User name");
 loginBox.addField("username", username);
 
 // Set focus to the user name
 username.focus();
 
 TextField password = new TextField("Password");
 loginBox.addField("password", password);
 
 Button login = new Button("Login");
 loginBox.getFooter().addComponent(login);
 
 // An additional component which natural focus order would
 // be after the button.
 CheckBox remember = new CheckBox("Remember me");
 loginBox.getFooter().addComponent(remember);
 
 username.setTabIndex(1);
 password.setTabIndex(2);
 remember.setTabIndex(3); // Different than natural place
 login.setTabIndex(4);
 

After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.

If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.

A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.

Specified by:
setTabIndex in interface Component.Focusable
Parameters:
tabIndex - the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.
See Also:
Component.Focusable.getTabIndex()

focus

public void focus()
Description copied from class: AbstractComponent
Sets the focus for this component if the component is Focusable.

Specified by:
focus in interface Component.Focusable
Overrides:
focus in class AbstractComponent
See Also:
FieldEvents, FieldEvents.FocusEvent, FieldEvents.FocusListener, FieldEvents.BlurEvent, FieldEvents.BlurListener

getState

protected com.vaadin.shared.ui.button.ButtonState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractComponent
Returns:
updated component shared state

getState

protected com.vaadin.shared.ui.button.ButtonState getState(boolean markAsDirty)
Description copied from class: AbstractClientConnector
Returns the shared state for this connector.

Overrides:
getState in class AbstractComponent
Parameters:
markAsDirty - true if the connector should automatically be marked dirty, false otherwise
Returns:
The shared state for this connector. Never null.
See Also:
AbstractClientConnector.getState()

setIcon

public void setIcon(Resource icon,
                    java.lang.String iconAltText)
Sets the component's icon and alt text. An alt text is shown when an image could not be loaded, and read by assisitve devices.

Parameters:
icon - the icon to be shown with the component's caption.
iconAltText - String to use as alt text

getIconAlternateText

public java.lang.String getIconAlternateText()
Returns the icon's alt text.

Returns:
String with the alt text

setIconAlternateText

public void setIconAlternateText(java.lang.String iconAltText)

setHtmlContentAllowed

public void setHtmlContentAllowed(boolean htmlContentAllowed)
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.

Parameters:
htmlContentAllowed - true if caption is rendered as HTML, false otherwise

isHtmlContentAllowed

public boolean isHtmlContentAllowed()
Return HTML rendering setting

Returns:
true if the caption text is to be rendered as HTML, false otherwise


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.