java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow JDIC arrow Adding Icons to System Tray
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Adding Icons to System Tray E-mail
User Rating: / 15
PoorBest 

The system tray is located in the Windows Taskbar, usually at the bottom right corner next to the clock. It contains miniature icons for easy access to system functions such as antivirus settings, printer, modem, sound volume, battery status, and more. Double-click or right-click an icon to view and access the details and controls. The system tray was first introduced with Microsoft Windows 95, and is now used in Windows 98, 98SE, Me, NT 4.0, 2000, and XP.

Since Java 1.5 does not have an api allowing you add icons to the system tray, you need to use a third party library which uses JNI (Java Native Interface) to be able to implement this functionality.

JDIC (JDesktop Integration Components) allows creation of a tray icon on the desktop (in the System Tray Area for Windows platforms, or in the Notification Area for Unix platforms), with a caption (text), an animated icon, and an associated Swing menu containing icons. It can also display a tooltip when the mouse hovers over the tray icon.

Following example shows how to implement such a functionality. You may look at JDIC documentation for further details.

import java.awt.event.*;
import javax.swing.*;
import org.jdesktop.jdic.tray.*;

public class TestTray {
    public static JMenuItem quit;
    
    public TestTray() {
        JPopupMenu menu = new JPopupMenu("Tray Icon Menu");
        menu.add(new JMenuItem("Test Item"));
        menu.addSeparator();
        JMenuItem quitItem = new JMenuItem("Quit");
        quitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                System.exit(0);
            }});
        menu.add(quitItem);
        
        // Resource file "duke.gif" must exist at the same directory
        // as this class file.
        ImageIcon icon = new ImageIcon("duke.gif");
        TrayIcon ti = new TrayIcon(icon, "JDIC Tray Icon API Test", menu);

        // Action listener for left click.
        ti.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, 
                    "JDIC Tray Icon API Test!""About",
                    JOptionPane.INFORMATION_MESSAGE);
            }
        });
               
        SystemTray tray = SystemTray.getDefaultSystemTray();
        tray.addTrayIcon(ti);
    }

    public static void main(String[] args) {
        new TestTray();
    }   
}


 Related Tips

 

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.