我正在编写这个非常基本的J2SE应用程序,它不时地向用户发出一些信息。目前我使用SystemTray和TrayIcon类来显示通知,但我对此并不满意。它不允许我调整通知,也不允许他们好看。
那么,有没有人知道一个易于使用的库来生成好的通知?
顺便说一句,我将移植到Linux(Ubuntu),但将在那里使用notify-OSD,这正是我需要的。
我正在编写这个非常基本的J2SE应用程序,它不时地向用户发出一些信息。目前我使用SystemTray和TrayIcon类来显示通知,但我对此并不满意。它不允许我调整通知,也不允许他们好看。
那么,有没有人知道一个易于使用的库来生成好的通知?
顺便说一句,我将移植到Linux(Ubuntu),但将在那里使用notify-OSD,这正是我需要的。
您可以使用 JCommunique 用于跨平台Java桌面通知。这是一个改编自的简短演示 例子 在维基上:
// makes a factory with the built-in clean theme
// themes are customizeable
NotificationFactory factory = new NotificationFactory(ThemePackagePresets.cleanLight());
// factories build notifications using a theme, while managers handle how
// how they appear on the screen
// this manager just simple pops up the notification in the specified location
// other managers do sliding, queues, etc.
NotificationManager plain = new SimpleManager(Location.NORTHEAST);
// creates a text notification; you can also have progress bar Notifications,
// icon Notifications, Notifications that ask for user feedback, etc.
TextNotification notification = factory.buildTextNotification("This is a title",
"This is a subtitle");
notification.setCloseOnClick(true);
// the notification will disappear after 2 seconds, or after you click it
plain.addNotification(notification, Time.seconds(2));
简短的忏悔:我也是这个项目的创造者。它是开源的,所以我没有从中获得任何收入。
其他一些图书馆可以看看:
我无法发布这些链接,因为我没有足够的声誉,但他们很容易在互联网上找到。 现在我会 尝试 与上述相比,客观地评估我自己的图书馆。请记住,这个列表有点广泛,因为我比其他人更了解我的项目。如果有什么我遗失的,请告诉我。
我不知道Java库是否抽象出所有特定于操作系统的桌面通知。但是如果你知道,你只能使用Ubuntu(也许是有限数量的其他操作系统),你可以创建一个自己的 Interface
并为特定的操作系统实现它。
/usr/bin/notify-send
通过 Runtime
喜欢这个: usr/bin/notify-send -t 30000 "Text1" "Text2" -i /path/to/48x48.png