JavaFX应用程序中的通知

Pho*_*ste 0 java javafx controlsfx

我想在JavaFX应用程序中为某些操作添加通知.例如成功连接到服务器,断开服务器等等...我尝试了来自ControlsFX的NotificationPane但是我在短时间延迟后无法隐藏栏.您似乎只能在用户交互后隐藏它.

如果你知道另一个类似甚至更好的图书馆,我很期待.

另外,我想让我的通知看起来像这样:IE通知

所以它不占用应用程序的整个宽度:)

谢谢

Jam*_*s_D 5

NotificationPane有一种hide()方法,你可以在你需要的任何延迟之后直接调用.所以你可以做到

NotificationPane notificationPane = ... ;

// show for 1 second:
notificationPane.show();
PauseTransition delay = new PauseTransition(Duration.seconds(1));
delay.setOnFinished(e -> notificationPane.hide());
delay.play();
Run Code Online (Sandbox Code Playgroud)

您可以通过向通知窗格添加填充来实现所需的布局(尽管我还没有对此进行测试):

notificationPane.setPadding(new Insets(0, 30, 0, 30));
Run Code Online (Sandbox Code Playgroud)