0

I am trying to implement a pop upp notification in JavaFx I am using this lib and according to that tutorial wrote this code:

    String title = "Well done boy!!";
    String message = "You've successfully created your first Tray Notification";

    TrayNotification tray = new TrayNotification();
    tray.setTitle(title);
    tray.setMessage(message);
    tray.setNotificationType(NotificationType.SUCCESS);
    tray.showAndWait();

but the code is throwing an Exception:

Caused by: java.lang.IllegalStateException: Toolkit not initialized at com.sun.javafx.application.PlatformImpl.runLater(Unknown Source) at com.sun.javafx.application.PlatformImpl.runLater(Unknown Source) at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(Unknown Source) at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(Unknown Source) at javafx.scene.control.Control.(Unknown Source) ... 15 more

Any suggetion why?

please note, the original code example is implemented like:

tray.setNotification(notification);

where notification is

but some how I can not import the class

 Notification notification = Notifications.SUCCESS;
  • Do you invoke the code in Platform.runLater ? – rvit34 Mar 10 '17 at 12:02
  • nope, in the main method of eclipse the code is runned as in the example posted above.... – Firewall-Alien Mar 10 '17 at 12:28
  • Subclass `Application` or create a new `new JFXPanel()` to have the Toolkit initialized. See http://stackoverflow.com/questions/11273773/javafx-2-1-toolkit-not-initialized and http://stackoverflow.com/questions/14025718/javafx-toolkit-not-initialized-when-trying-to-play-an-mp3-file-through-mediap – DVarga Mar 10 '17 at 12:34

1 Answers1

0

try to use constructor for creating.ıt works for me that way. Did you add the library from the module settings?

Ex:

 TrayNotification tray = new TrayNotification("Test", "mesaj", NotificationType.SUCCESS);        
    tray.showAndWait();
Dahico
  • 66
  • 2
  • 12