troubleshooting Question

having troubles getting icon to show up in the system tray

Avatar of jvilla1983
jvilla1983 asked on
Unix OSJava
6 Comments2 Solutions553 ViewsLast Modified:
OK.. My code here that I derived from another website isnt showing the icon that I chose to use for my system tray. Is there any way that someone could help me out with getting it to show up there?
package main;
import java.awt.*;
import java.awt.event.*;
public class NewControllerClass {
    public NewControllerClass() {
        final TrayIcon trayIcon;
        if ( SystemTray.isSupported() ) {
            SystemTray tray = SystemTray.getSystemTray();
            Image image = Toolkit.getDefaultToolkit().getImage("bomb.gif");
            MouseListener mouseLIstener = new MouseListener() {
                public void mouseClicked(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse Clicked!");
                public void mouseEntered(MouseEvent e) {
                    System.out.println("Tray Icon = Mouse Entered!");
                public void mouseExited(MouseEvent e) {
                    System.out.println("Tray icon - mouse exited!");
                public void mousePressed(MouseEvent e) {
                    System.out.println("Tray icon - mouse pressed");
                public void mouseReleased(MouseEvent e) {
                    System.out.println("Tray icon - mouse released");
            ActionListener exitListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Exit.. ");
            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("Exit");
            trayIcon = new TrayIcon(image, "Tray Demo", popup);
            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    trayIcon.displayMessage("action Event",
                        "an action has been performed",
            try {
            } catch ( AWTException e ) {
                System.err.println("TrayIcon could not be added.");
        } else {
            // do nothing..

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros