Search code examples
javafx-2javafxjavafx-8

How to create user notification message similar to JGrowl


I started to work to user notification message similar to JGrowl for JavaFX.

public void newMessage()
{

    final Stage newConnDialog = new Stage();
    newConnDialog.initStyle(StageStyle.UNDECORATED);
    newConnDialog.initModality(Modality.WINDOW_MODAL);

    // Set pisition
    newConnDialog.setX(1050); //secondStage.setX(primaryStage.getX() + 250);
    newConnDialog.setY(150);

    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(5);
    grid.setVgap(5);
    grid.setPadding(new Insets(20, 20, 20, 20));

    // text
    Text productName = new Text("Test");
    productName.setFont(Font.font("Verdana", 12));
    grid.add(productName, 0, 2);

    // Configure dialog size and background color
    Scene aboutDialogScene = new Scene(grid, 200, 100, Color.WHITESMOKE);
    newConnDialog.setScene(aboutDialogScene);
    newConnDialog.show();
}

I have a basic knowledge about JavaFX. Can you give me some basic advice what will be the best way to implement this component. For example do I need to create new Stage or I can use other component as stage. How I can hide the component after 10 seconds activity and etc. Any advice will be highly appreciated.

P.S. I found this example for JavaFX 1.3 Maybe it can be rewritten for JavaFX 2.2?


Solution

  • This is one possible solution by using the Enzo library:

    // Create a custom Notification without icon  Notification info = new
    Notification("Title", "Info-Message");
    
    // Show the custom notification   
    Notifier.INSTANCE.notify(info);
    
    // Show a predefined Warning notification
    Notifier.INSTANCE.notifyWarning("This is a warning");
    

    enter image description here

    Source