Reputation: 19
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?
Upvotes: 1
Views: 501
Reputation: 1270
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.
Upvotes: 0