![](/img/trans.png)
[英]IllegalStateException when using JavaFX Alert in init() because not on FX application thread
[英]IllegalStateException when using the Tray Notification in java Fx?
我正在尝试在JavaFx中实现pop upp通知,我正在使用此lib,并根据该教程编写了以下代码:
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();
但是代码抛出异常:
引起原因:java.lang.IllegalStateException:未在com.sun.javafx.application.PlatformImpl.runLater(未知源)处的com.sun.javafx.application.PlatformImpl.runLater(未知源)处初始化工具包com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(未知源),位于javafx.scene.control.Control。(未知源)处的.application.PlatformImpl.setPlatformUserAgentStylesheet(未知源)... 15更多
有什么建议吗?
请注意,原始代码示例的实现方式如下 :
tray.setNotification(notification);
通知在哪里
但是有些我无法导入课程
Notification notification = Notifications.SUCCESS;
尝试使用构造函数进行创建。那样为我工作。 您是否从模块设置中添加了库?
例如:
TrayNotification tray = new TrayNotification("Test", "mesaj", NotificationType.SUCCESS);
tray.showAndWait();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.