Notifications

Notifications are small dialogs that appear on the view to tell the user something.

Create a simple notification:

Notification.show("Hello!");

Result: A small notification appears at the bottom left of the screen.

image not found

Create and configure a notification:

final Notification myNotification = new Notification();
myNotification.setDuration(2000);                                  // Zeige die Notification für 2 Sekunden
myNotification.setText("Hello!");                                  // Setze den Text auf "Hello!"
myNotification.setPosition(Position.TOP_START);                    // Die Notification soll von links oben erscheinen
myNotification.addThemeVariants(NotificationVariant.LUMO_SUCCESS); // Die Notification soll eine SUCCESS Nachricht sein

// Zeige die Notification an
myNotification.open();

Result:

image not found

Notifications are not limited to just a text, but can also include whole views and layouts.

Example:

final VerticalLayout layout = new VerticalLayout();
layout.add(new Button("Test Button"));
layout.add(new Label("You can add more than just text!"));

final Notification myNotification = new Notification(layout);
myNotification.open();

Result:

image not found