Notification in a JavaFX app

北城余情 提交于 2019-12-25 07:08:38

问题


I would like to add a notification to some actions in my JavaFX application. Such as a successful connection to a server, a disconnection to a server, etc ... I tried the NotificationPane from ControlsFX but I can't hide the bar after a short time delay. It seems that you can only hide it after an user interaction.

If you know another library who does something similar or even better, I'm looking forward to it.

Plus I would like to make my notifications look like that :

so it doesn't take the whole width of the application :)

Thanks


回答1:


NotificationPane has a hide() method that you can call directly, after whatever delay you need. So you can just do

NotificationPane notificationPane = ... ;

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

You can probably achieve the layout you need by adding padding to the notification pane (though I haven't tested this):

notificationPane.setPadding(new Insets(0, 30, 0, 30));



回答2:


You can use if you want the TrayIcon.displayMessage. But you cant realy style this Messages.

Otherwise you can implement this yourself.

doesn't sounds that complicated.

Just create a new Stage and show it with your Message then after a delay hide the Stage and your done.



来源:https://stackoverflow.com/questions/35319671/notification-in-a-javafx-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!