Tutorial by Examples

Buttons fire action events when they are activated (e.g. clicked, a keybinding for the button is pressed, ...). button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); ...
Buttons can have a graphic. graphic can be any JavaFX node, like a ProgressBar button.setGraphic(new ProgressBar(-1)); An ImageView button.setGraphic(new ImageView("images/icon.png")); Or even another button button.setGraphic(new Button("Nested button"));
Creation of a Button is simple: Button sampleButton = new Button(); This will create a new Button without any text or graphic inside. If you want to create a Button with a text, simply use the constructor that takes a String as parameter (which sets the textProperty of the Button): Button samp...
Button API provides an easy way to assign common keyboard shortcuts to buttons without the need to access accelerators' list assigned to Scene or explicitly listening to the key events. Namely, two convenience methods are provided: setDefaultButton and setCancelButton: Setting setDefaultButton ...

Page 1 of 1