DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Java6 Create Trayicon
// description of your code here
public void initIcon()
{
if (SystemTray.isSupported())
{
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage(ICON_FILE);
popupMenu = new PopupMenu();
trayIcon = new TrayIcon(image, "Daniels personal quick-scripts", popupMenu);
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// trayIcon.displayMessage("Action Event", "An Action Event Has Been Performed!", TrayIcon.MessageType.INFO);
}
};
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(actionListener);
trayIcon.addMouseListener(this);
try
{
tray.add(trayIcon);
} catch (AWTException e)
{
System.err.println("TrayIcon could not be added.");
}
} else
{
// System Tray is not supported
System.out.println("No system tray supported");
}
}





