On Action

p338 Add ActionApp main class with button action listener method.
 * FXML on action method is defined in ...
 * Scene Builer 'on Action'

package com.minte9.javafx.on_action;
import javafx.fxml.FXML;

public class ActionApp {
    public static void main(String[] args) {

    @FXML void buttonPressed() { // Look Here
        System.out.println("button pressed");
... 9 lines


Add ActionAppGui class that loads fxml file.
 * Gui class with button.xml loader

package com.minte9.javafx.on_action;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class ActionAppGui extends Application {

    public static void main(String[] args) {
    @Override public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("button.fxml"));

        stage.setTitle("Button Event FXML");
        stage.setScene(new Scene(root));;
... 15 lines

Scene Builder

Set controller and button method (buttonPressed).
Containers / Add VBox 
Controllers / Add Button
Controller / ControllerClass ... com.minte9.javafx.on_action.ActionApp

Button / Inspector / Code / On Action ... buttonPressed

Preview / Show Preview in Window
View / Show sample Controller Skeleton

Save ... button.fxml
... 2 lines


Each value for a JavaFX object is used to set object's instance variables.
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.VBox?>

<VBox maxHeight="-Infinity" maxWidth="-Infinity" 
   minHeight="-Infinity" minWidth="-Infinity" 
   prefHeight="400.0" prefWidth="600.0" 
   xmlns="" xmlns:fx="" 

      <Button mnemonicParsing="false" onAction="#buttonPressed" text="Button" />
... 7 lines

Questions     github JavaFX
Change Listener

        A B C D E F