Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 664
user1285928 Avatar asked Jul 05 '13 14:07

user1285928


2 Answers

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

like image 74
Peter Penzov Avatar answered Oct 01 '22 12:10

Peter Penzov


You can use the ControlsFx library to create notifications http://docs.controlsfx.org/org/controlsfx/control/NotificationPane.html

like image 39
Zvonimir Lozancic Avatar answered Oct 01 '22 11:10

Zvonimir Lozancic