开发者

How do I render nice desktop notifications from Java? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I am writing this very basic J2SE application which alerts the user with some info every now and then. Currently I am using the SystemTray and TrayIcon classes to show notifications, but I am not really pleased with that. It does not allow me to tweak the notifications, nor gives them a good look.

So, does anyone know an easy to use library to generate nice notifications?

btw, I will be porting to Linux (Ubuntu) to, but will开发者_如何学运维 be using notify-OSD there, which is exactly what I need.


Shameless plug: I've just released a project called Twinkle that is pretty much Growl for Java Swing.


I' not aware of a Java library abstracting all OS specific desktop notifications. But if you know, you are limited to Ubuntu (and perhaps a limited number of other OS), you can create a own Interface and implement it for the specific OS.

  • Ubuntu: You can access /usr/bin/notify-send via Runtime like this: usr/bin/notify-send -t 30000 "Text1" "Text2" -i /path/to/48x48.png
  • Mac OSX: Java Growl API

For JAVA implementations you may look at Jazz or Mylyn (see Java Desktop Notifications).


You can use JCommunique for cross-platform Java desktop notifications. Here is a short demo adapted from the examples on the wiki:

// 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));

Brief confession: I also am the creator of this project. It's open source so I don't get any revenue from it.

Some other libraries to have a look at:

Twinkle

  • This is already mentioned in another answer so I won't say too much about it. I tried the Java Webstart demo and it looked pretty nice. It allows for some more complicated background color options such as gradients that JCommunique doesn't have.
  • About 3,500 lines.
  • Has a bunch of fancy styling options such as round vs. rectangle close buttons, gradient vs. solid color, and light vs. dark notifications. However, has just one sequential manager.
  • The wiki has links to javadocs and a getting started document.
  • No external dependencies (I think?).

JCarrierPigeon

  • Very lightweight. Looking at the jar, it has just six classes.
  • Depends on the "Timing Framework" library.
  • The website shows that it can do some sliding in effects, but I don't think it does fading or other types of animations.

JTelegraph

  • Requires JCarrierPigeon and "Timing Framework" in the classpath to build
  • Has dozens of nice-looking icons included with the project. I'm not sure how these are licensed, but they could be useful if you don't have your own.
  • As far as I can tell, it doesn't include many more features than those provided in JCarrierPigeon. It mainly includes a bunch of built in icons and a different API.

I can't post links to these since I don't have enough reputation, but they are easy to find on the internet. Now I will try to objectively evaluate my own library in comparison with the above. Please keep in mind that this list is a bit more extensive since I know more about my project than the others. Let me know if there is anything that I'm missing.

JCommunique

  • Many features. As far as Notifications go, there are TextNotifications, IconNotifications, AcceptNotifications, and ProgressNotifications (show a progress bar). NotificationManagers handle how Notifications show. These include SimpleManager, QueueManager (scrolls down old Notifications to reveal new ones), SlideManager (slides Notifications into position), and SequenceManager (only shows a Notification when the previous one has disappeared).
  • Relatively large. I think it clocks in at about 2,500 lines in total.
  • Has a wiki with a number of examples.
  • Notifications look a bit plain because they can only be one solid color. Twinkle wins in this respect; it has gradients and outlines around its notifications.
  • A handful of built-in themes. At time of writing these include dark, light, and aqua. You can also add your own.
  • No external dependencies other than Java.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜