Created
August 29, 2011 23:06
-
-
Save gseitz/1179658 to your computer and use it in GitHub Desktop.
Poor man's growl-like notification on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.TrayIcon | |
import java.awt.SystemTray.{getSystemTray => tray} | |
import java.awt.Toolkit.{getDefaultToolkit => toolkit} | |
import java.net.URL | |
object Notification { | |
private lazy val scalaIcon = { | |
// of course we use the logo of our favorite language ;) | |
val img = toolkit.getImage(new URL("http://www.scala-lang.org/sites/default/files/favicon.gif")) | |
new TrayIcon(img) | |
} | |
def show(caption: String, text: String, messageType: TrayIcon.MessageType = TrayIcon.MessageType.INFO, icon: TrayIcon = scalaIcon) { | |
tray.add(icon) | |
icon.displayMessage(caption, text, messageType) | |
// On windows, the message balloon is removed, as soon as the icon is removed. That's why we just wait couple of seconds here. | |
Thread.sleep(5000) | |
tray.remove(icon) | |
} | |
} | |
Notification.show("foo", "bar") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment