Example usage for java.awt SystemTray removePropertyChangeListener

List of usage examples for java.awt SystemTray removePropertyChangeListener

Introduction

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

Prototype

public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) 

Source Link

Document

Removes a PropertyChangeListener from the listener list for a specific property.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
        return;//from ww  w .j  a v a2  s .c  o m
    }
    SystemTray tray = SystemTray.getSystemTray();

    PropertyChangeListener pcl;
    pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            System.out.println("Property changed = " + pce.getPropertyName());
            TrayIcon[] tia = (TrayIcon[]) pce.getOldValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }

            tia = (TrayIcon[]) pce.getNewValue();
            if (tia != null) {
                for (int i = 0; i < tia.length; i++)
                    System.out.println(tia[i]);
            }
        }
    };
    tray.addPropertyChangeListener("trayIcons", pcl);

    Dimension size = tray.getTrayIconSize();

    BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, size.width, size.height);
    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

    Thread.sleep(3000);
    tray.remove(icon);

    tray.removePropertyChangeListener("trayIcons", pcl);

    Thread.sleep(3000);
    System.exit(0);
}