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:
    • 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:
  • 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.
      Returns:
      the property to indicate that the button has been "armed"
      See Also:
    • isArmed

      public final boolean isArmed()
      Gets the value of the armed property.
      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.
      Returns:
      the value of the armed property
      See Also:
    • 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.
      Returns:
      the property to represent the button's action, which is invoked whenever the button is fired
      See Also:
    • setOnAction

      public final void setOnAction(EventHandler<ActionEvent> value)
      Sets the value of the onAction property.
      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.
      Parameters:
      value - the value for the onAction property
      See Also:
    • getOnAction

      public final EventHandler<ActionEvent> getOnAction()
      Gets the value of the onAction property.
      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.
      Returns:
      the value of the onAction property
      See Also:
    • 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().