Remove Icon from TrayIcon : TrayIcon « JDK 6 « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » JDK 6 » TrayIconScreenshots 
Remove Icon from TrayIcon
 

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 SystemTrayDemo1 {
  public static void main(String[] argsthrows 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) {
          System.out.println("Old tray icon array contents: ");
          for (int i = 0; i < tia.length; i++)
            System.out.println(tia[i]);
          System.out.println();
        }

        tia = (TrayIcon[]) pce.getNewValue();
        if (tia != null) {
          System.out.println("New tray icon array contents: ");
          for (int i = 0; i < tia.length; i++)
            System.out.println(tia[i]);
          System.out.println();
        }
      }
    };
    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(00, size.width, size.height);
    g.setColor(Color.yellow);
    int ovalSize = (size.width < size.height? size.width : size.height;
    ovalSize /= 2;
    g.fillOval(size.width / 4, size.height / 4, ovalSize, ovalSize);

    TrayIcon icon = null;
    tray.add(icon = new TrayIcon(bi));

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

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

}

        
Related examples in the same category
1. Create Tray Icon
2. Add mouse listener to TrayIcon
3. Add Mouse motion listener to TrayIcon
4. Using system tray
5. Demonstrating a System Tray That Responds to Selection
6. Add PropertyChangeListener to TrayIcon
w_ww_.ja___v_a2__s_.c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.