FXML_PlatFormExitEvent
 
 Code


--main clasd-
package javafxtemplate1;
//Grid_VBOx_Thread
import java.io.IOException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

public class JavaFXTemplate1 extends Application {

@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("JavaFXMLDoc1.fxml"));
//Scene scene = new Scene(root);

//Group root = new Group();
Scene scene = new Scene(root, 450,300);
primaryStage.setScene(scene);
primaryStage.setTitle("FXML BorderPane::Label, Button");
primaryStage.show();
}
//

//
public static void main(String[] args) {
Application.launch(args);
}

}


----JavaFXMLDoc1.xml----
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>

<BorderPane id="BorderPane" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxtemplate1.JavaFXMLDoc1Controller">
<stylesheets>
<URL value="@javafxmldoc1.css"/>
</stylesheets>
<top>
<Button layoutX="126" layoutY="90" text="Start!" onAction="#startTask" fx:id="button1" />

</top>
<center>
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label1" />
</center>
<bottom>
<Button layoutX="146" layoutY="190" text="Exit!" onAction="#endTask" fx:id="button2" />
</bottom>
</BorderPane>
---JavaFXMLDoc1Controller.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxtemplate1;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.stage.Stage;


public class JavaFXMLDoc1Controller implements Initializable {

/**
* Initializes the controller class.
*/
@FXML
private Label label1, label2;
@FXML
private Stage primaryStage;
@FXML
private void startTask(ActionEvent event) {
//System.out.println("You clicked me!");
label1.setText("Hello World!");
}

@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
//label2.setText("Initialized ");

}

@FXML
private void endTask(ActionEvent event) {
//System.out.println("You clicked me!");
Platform.exit();
}

}

Displays:

Start event:

Exit event, will close the application.