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)
    • command

      public final ObjectProperty<Command<?>> commandProperty
      The button's command, which is invoked whenever the button is fired.

      If a command is set on the button, Node.disableProperty() is automatically bound to Command.executableProperty() such that the button is enabled if the command can be executed, and is disabled if the command cannot be executed. Any previous binding is removed.

      See Also:
      getCommand(), setCommand(Command)
    • commandParameter

      public final ObjectProperty<Object> commandParameterProperty
      The button's command parameter. When the command is invoked, this parameter will be passed to the command implementation.
      See Also:
      getCommandParameter(), setCommandParameter(Object)
  • 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.
    • commandProperty

      public final ObjectProperty<Command<?>> commandProperty()
      The button's command, which is invoked whenever the button is fired.

      If a command is set on the button, Node.disableProperty() is automatically bound to Command.executableProperty() such that the button is enabled if the command can be executed, and is disabled if the command cannot be executed. Any previous binding is removed.

      See Also:
      getCommand(), setCommand(Command)
    • getCommand

      public Command<?> getCommand()
      Gets the value of the property command.
      Property description:
      The button's command, which is invoked whenever the button is fired.

      If a command is set on the button, Node.disableProperty() is automatically bound to Command.executableProperty() such that the button is enabled if the command can be executed, and is disabled if the command cannot be executed. Any previous binding is removed.

    • setCommand

      public void setCommand​(Command<?> command)
      Sets the value of the property command.
      Property description:
      The button's command, which is invoked whenever the button is fired.

      If a command is set on the button, Node.disableProperty() is automatically bound to Command.executableProperty() such that the button is enabled if the command can be executed, and is disabled if the command cannot be executed. Any previous binding is removed.

    • commandParameterProperty

      public final ObjectProperty<Object> commandParameterProperty()
      The button's command parameter. When the command is invoked, this parameter will be passed to the command implementation.
      See Also:
      getCommandParameter(), setCommandParameter(Object)
    • getCommandParameter

      public Object getCommandParameter()
      Gets the value of the property commandParameter.
      Property description:
      The button's command parameter. When the command is invoked, this parameter will be passed to the command implementation.
    • setCommandParameter

      public void setCommandParameter​(Object commandParameter)
      Sets the value of the property commandParameter.
      Property description:
      The button's command parameter. When the command is invoked, this parameter will be passed to the command implementation.
    • 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().

    • fireEvent

      public final void fireEvent​(Event event)
      Description copied from class: Node
      Fires the specified event. By default the event will travel through the hierarchy from the stage to this node. Any event filter encountered will be notified and can consume the event. If not consumed by the filters, the event handlers on this node are notified. If these don't consume the event either, the event will travel back the same path it arrived to this node. All event handlers encountered are called and can consume the event.

      This method must be called on the FX user thread.

      Overrides:
      fireEvent in class Node
      Parameters:
      event - the event to fire
    • 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