Java SystemTray .removePropertyChangeListener (String propertyName, PropertyChangeListener listener)

Syntax

SystemTray.removePropertyChangeListener(String propertyName, PropertyChangeListener listener) has the following syntax.

public void removePropertyChangeListener(String propertyName,     PropertyChangeListener listener)

Example

In the following code shows how to use SystemTray.removePropertyChangeListener(String propertyName, PropertyChangeListener listener) method.


/*from   ww w.  ja  va  2  s .c  o m*/

import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public class Main {
  public static void main(String[] args) throws Exception {
    if (!SystemTray.isSupported()) {
      return;
    }
    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);
  }

}




















Home »
  Java Tutorial »
    java.awt »




BasicStroke
BorderLayout
CardLayout
Color
Cursor
Desktop
DesktopManager
DisplayMode
EventQueue
FlowLayout
FocusTraversalPolicy
Font
FontMetrics
GradientPaint
Graphics
Graphics2D
GraphicsConfiguration
GraphicsDevice
GraphicsEnvironment
GridBagConstraints
GridBagLayout
GridLayout
Image
ItemSelectable
KeyboardFocusManager
LayoutManager
LayoutManager2
Point
Rectangle
Robot
Shape
SplashScreen
SystemColor
SystemTray
TexturePaint
TrayIcon
Toolkit
Transparency