Class ButtonBase

All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
Button, CheckBox, Hyperlink, MenuButton, ToggleButton

public abstract class ButtonBase
extends Labeled
Base class for button-like UI Controls, including Hyperlinks, Buttons, ToggleButtons, CheckBoxes, and RadioButtons. The primary contribution of ButtonBase is providing a consistent API for handling the concept of button "arming". In UIs, a button will typically only "fire" if some user gesture occurs while the button is "armed". For example, a Button may be armed if the mouse is pressed and the Button is enabled and the mouse is over the button. In such a situation, if the mouse is then released, then the Button is "fired", meaning its action takes place.
Since:
JavaFX 2.0
  • Property Details

    • armed

      public final ReadOnlyBooleanProperty armedProperty
      Indicates that the button has been "armed" such that a mouse release will cause the button's action to be invoked. This is subtly different from pressed. Pressed indicates that the mouse has been pressed on a Node and has not yet been released. arm however also takes into account whether the mouse is actually over the button and pressed.
      See Also:
      isArmed()
    • onAction

      public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty
      The button's action, which is invoked whenever the button is fired. This may be due to the user clicking on the button with the mouse, or by a touch event, or by a key press, or if the developer programmatically invokes the fire() method.
      See Also:
      getOnAction(), setOnAction(EventHandler)
  • Constructor Details

    • ButtonBase

      public ButtonBase()
      Create a default ButtonBase with empty text.
    • ButtonBase

      public ButtonBase​(String text)
      Create a ButtonBase with the given text.
      Parameters:
      text - null text is treated as the empty string
    • ButtonBase

      public ButtonBase​(String text, Node graphic)
      Create a ButtonBase with the given text and graphic.
      Parameters:
      text - null text is treated as the empty string
      graphic - a null graphic is acceptable
  • Method Details

    • armedProperty

      public final ReadOnlyBooleanProperty armedProperty()
      Indicates that the button has been "armed" such that a mouse release will cause the button's action to be invoked. This is subtly different from pressed. Pressed indicates that the mouse has been pressed on a Node and has not yet been released. arm however also takes into account whether the mouse is actually over the button and pressed.
      See Also:
      isArmed()
    • isArmed

      public final boolean isArmed()
      Gets the value of the property armed.
      Property description:
      Indicates that the button has been "armed" such that a mouse release will cause the button's action to be invoked. This is subtly different from pressed. Pressed indicates that the mouse has been pressed on a Node and has not yet been released. arm however also takes into account whether the mouse is actually over the button and pressed.
    • onActionProperty

      public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()
      The button's action, which is invoked whenever the button is fired. This may be due to the user clicking on the button with the mouse, or by a touch event, or by a key press, or if the developer programmatically invokes the fire() method.
      See Also:
      getOnAction(), setOnAction(EventHandler)
    • setOnAction

      public final void setOnAction​(EventHandler<ActionEvent> value)
      Sets the value of the property onAction.
      Property description:
      The button's action, which is invoked whenever the button is fired. This may be due to the user clicking on the button with the mouse, or by a touch event, or by a key press, or if the developer programmatically invokes the fire() method.
    • getOnAction

      public final EventHandler<ActionEvent> getOnAction()
      Gets the value of the property onAction.
      Property description:
      The button's action, which is invoked whenever the button is fired. This may be due to the user clicking on the button with the mouse, or by a touch event, or by a key press, or if the developer programmatically invokes the fire() method.
    • arm

      public void arm()
      Arms the button. An armed button will fire an action (whether that be the action of a Button or toggling selection on a CheckBox or some other behavior) on the next expected UI gesture. Note: This function is intended to be used by experts, primarily by those implementing new Skins or Behaviors. It is not common for developers or designers to access this function directly.
    • disarm

      public void disarm()
      Disarms the button. See arm(). Note: This function is intended to be used by experts, primarily by those implementing new Skins or Behaviors. It is not common for developers or designers to access this function directly.
    • fire

      public abstract void fire()
      Invoked when a user gesture indicates that an event for this ButtonBase should occur.

      If invoked, this method will be executed regardless of the status of arm().

    • executeAccessibleAction

      public void executeAccessibleAction​(AccessibleAction action, Object... parameters)
      This method is called by the assistive technology to request the action indicated by the argument should be executed.

      This method is commonly overridden by subclasses to implement action that are required for a specific role.
      If a particular action is not handled, the superclass implementation must be called.

      Overrides:
      executeAccessibleAction in class Control
      Parameters:
      action - the action to execute
      parameters - optional list of parameters
      See Also:
      AccessibleAction