If you guys are working with JavaFX and creating a small application or creating an enterprise application then definitely you need to show an alert box on particular user action like a button click or doing some validation on form input, then there is a need to show alert popup in this case.I am going to explain how to create an alert box in JavaFX application. Also, I have given sample code so you can directly use this code snippet in your application. I made it simple and clear. Also, there is an attachment to sample project code so you guys can download as well. I am using NetBeans IDE to create this example.
There are five types of Alert Type available for use. Here I have given the code for each one.
1) AlertType.CONFIRMATION
Type 1: Confirmation box
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle(“Confirmation Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Confirmation Box Example”);
alert.setContentText(contentText);
alert.showAndWait();
2) AlertType.ERROR
Type 2: Error box
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(“ERROR Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Error Box Example”);
alert.setContentText(contentText);
alert.showAndWait();
3) AlertType. INFORMATION
Type 3: Information box
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(“Information Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Information Box Example”);
alert.setContentText(contentText);
alert.showAndWait();
4) AlertType.NONE
Type 4: Alert Type None
Alert alert = new Alert(AlertType.NONE);
alert.setTitle(“Simple Alert Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Simple Alert box Example”);
alert.setContentText(contentText);
alert.showAndWait();
alert.setTitle(“Simple Alert Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Simple Alert box Example”);
alert.setContentText(contentText);
alert.showAndWait();
5) AlertType.WARNING
Type 5: Alert Type Warning
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle(“Warning Alert Box”);
alert.setHeaderText(“COOL IT HELP”);
String contentText = String.format(“This is Warning Alert box Example”);
alert.setContentText(contentText);
alert.showAndWait();