JavaFX: Creating a second stage to show alert

This entry is part 34 of 55 in the series JavaFX

We have always used alert box to show an alert message in web development but for JavaFX, we have to roll out our own alert box.

The usual method for most JavaFX developers is to create a second stage as shown in the example below.

In this example, we will create an AlertBox class and put the class in a separate JavaFX class file.

Main Application
package javafxapplication26;

import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;

public class JavaFXApplication26 extends Application {

    public void start(Stage stage) {

        Button btn = new Button();
        btn.setText("Click Me");
        btn.setOnAction(e -> buttonClick());

        BorderPane pane = new BorderPane();

        Scene scene = new Scene(pane, 500, 400);

        stage.setTitle("Show Alert");;

    public void buttonClick() {"This Is An Alert!", "Alert!");


    public static void main(String[] args) {


You can add a class file and name the file as shown below.
package javafxapplication26;

import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.geometry.*;

public class AlertBox       
    public static void show(String message, String title)    
        Stage stage = new Stage();       

        Label lbl = new Label();       

        Button btnOK = new Button();       
        btnOK.setOnAction(e -> stage.close());       

        VBox pane = new VBox(20);       
        pane.getChildren().addAll(lbl, btnOK);

        Scene scene = new Scene(pane);       



jQuery UI & Dialog: Modal Dialog Box Alert

This entry is part 2 of 6 in the series jQuery UI Dialog

jQuery UI Dialog – Modal message

Use a modal dialog to explicitly acknowledge information or an action before continuing their work.

Set the modal option to true, and specify a primary action (Ok) with the buttons option.

<!doctype html>
<html lang='en'>
    <meta charset='utf-8'>
    <title>jQuery UI Dialog - Modal message</title>
    <link rel='stylesheet' href='//'>
    <script src='//'></script>
    <script src='//'></script>
    <link rel='stylesheet' href=''>
        $(function () {
                modal: true,
                buttons: {
                    Ok: function () {

<div id='dialog-message' title='Download complete'>
        <span class='ui-icon ui-icon-circle-check' style='float:left; margin:0 7px 50px 0;'></span>
        Your files have downloaded successfully into the My Downloads folder.

        Currently using <b>36% of your storage space</b>.

<p>Modal Dialog Box Alert Demo</p>

Try The Code