Example usage for java.awt TrayIcon TrayIcon

List of usage examples for java.awt TrayIcon TrayIcon

Introduction

In this page you can find the example usage for java.awt TrayIcon TrayIcon.

Prototype

public TrayIcon(Image image, String tooltip) 

Source Link

Document

Creates a TrayIcon with the specified image and tooltip text.

Usage

From source file:ui.main.MainViewController.java

private void showNotifications(String chat, String message) {
    // a general method for view notifications -> windows notification
    if (!isnotifiable.isSelected()) {
        return;/*from w w  w .j ava 2s  . co  m*/
    }
    URL url = System.class.getResource("/resources/LogoTransparent.png");
    java.awt.Image image = Toolkit.getDefaultToolkit().getImage(url);
    TrayIcon trayIcon = new TrayIcon(image, "Instant Messenger Plus");
    if (SystemTray.isSupported()) {
        SystemTray tray = SystemTray.getSystemTray();

        trayIcon.setImageAutoSize(true);
        try {
            tray.add(trayIcon);

        } catch (AWTException e) {
            System.err.println("TrayIcon could not be added.");
        }

        trayIcon.displayMessage("IMP: " + chat, message, TrayIcon.MessageType.INFO);
    }
}