1

I'm building an app with javafx that need to have same buttons in toolbar and in menu. So it's easier to use abstract actions, like swing has. So my question is, does javaFx has something like that?

RBT
  • 24,161
  • 21
  • 159
  • 240
Filip Antic
  • 19
  • 1
  • 1

1 Answers1

0

Yes, indeed, there is something like this in the ControlsFX library: the Action class.

"An action in JavaFX can be used to separate functionality and state from a control. For example, if you have two or more controls that perform the same function (e.g. one in a Menu and another on a toolbar), consider using an Action object to implement the function. An Action object provides centralized handling of the state of action-event-firing components such as buttons, menu items, etc. The state that an action can handle includes text, graphic, long text (i.e. tooltip text), and disabled."

example for handling the action event of a button:

    @FXML
 private void handleButtonAction(ActionEvent event) {
     // Button was clicked, do something...
     outputTextArea.appendText("Button Action\n");
 }

check out this for more info. Hope i have helped.

fabian
  • 80,457
  • 12
  • 86
  • 114
Gewure
  • 1,208
  • 18
  • 31
  • 6
    Note though that this is not part of JavaFX, but is part of a third-party library. – James_D Jan 20 '17 at 01:15
  • 1
    Thanks a lot i will try it. :) – Filip Antic Jan 21 '17 at 06:09
  • 1
    This answer is super misleading since JavaFX itself has no built-in Action class like Swing has that let's you share actions between components (like a button and menu item that does the same thing) – Michael Mar 19 '22 at 23:55