Over a million developers have joined DZone.

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");
		}
	}



Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}