Skip to content

Instantly share code, notes, and snippets.

@gseitz
Created August 29, 2011 23:06
Show Gist options
  • Save gseitz/1179658 to your computer and use it in GitHub Desktop.
Save gseitz/1179658 to your computer and use it in GitHub Desktop.
Poor man's growl-like notification on windows
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