Notifications not showing or showing only on the bottom of page

I would like to create a simple notircation - I’ve copied the code from the example, but no matter what I do, the notification shows up on the bottom of the page - and the user the user does not even know it exists unless they scroll to it. And then - it’s formatted rather strange…

private void notifyUser(String msg) {
log.info(“notify users with msg:{}”, msg);
Notification notification = new Notification();
Div text = new Div(new Text(msg));

    Button closeButton = new Button(new Icon("lumo", "cross"));
    closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY_INLINE);
    closeButton.setAriaLabel("Close");
    closeButton.addClickListener(event -> {
        notification.close();
    });
    notification.setPosition(Notification.Position.MIDDLE);
    notification.addThemeVariants(NotificationVariant.LUMO_CONTRAST);
    notification.add(text, closeButton);
    notification.open();
    return;
}

Your code is working fine.

The problem must be in the surrounding code where you call notifyUser()

Can you share a reproducible example?

I guess it was not code related at all, but the way I modified the theme. I went back to my default theme and all is working as expected.

1 Like