Add an icon/image to beside text as a part of a menuItem in PopupMenu
<p>I am creating a small program for my system tray in which it gives some information and displays an icon in the popup menu beside text. I have tried to add an icon using the JMenuItem but then I cannot add it the PopupMenu. Nor if I use a menuItem I cannot add an icon.</p>

<p>Here is my code so far:</p>

<pre><code>import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//......


public class Interface 
{
    public static void mainInterface()
    {
        if(!SystemTray.isSupported())
        {
            System.out.println("System tray not supported! This program can only be used on Windows.");
            return ;
        }
        SystemTray systemTray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage("src/icon.png");

        PopupMenu trayPopupMenu = new PopupMenu();

        MenuItem close = new MenuItem("Close");
        MenuItem CMItem = new MenuItem("test1", new ImageIcon("src/greenIcon.png"));
        MenuItem HerItem = new MenuItem("test2", new ImageIcon("src/greenIcon.png"));


        close.addActionListener(new ActionListener() 
        {
            @Override
            public void actionPerformed(ActionEvent e) 
            {
                System.exit(0);             
            }
        });
        trayPopupMenu.add(close);
        trayPopupMenu.add(CMItem);
        trayPopupMenu.add(HerItem);
        TrayIcon trayIcon = new TrayIcon(image, "Status", trayPopupMenu);

        trayIcon.setImageAutoSize(true);

        try
        {
            systemTray.add(trayIcon);
        }catch(AWTException awtException)
        {
            awtException.printStackTrace();
        }
        System.out.println("end of main");
    }
}
</code></pre>

<p>The above code will not run because of the icon portion in the menuItem objects. Can someone help me with putting the icon beside the text in the menu? </p>

<p>Edit:</p>

<pre><code>Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The constructor MenuItem(String, ImageIcon) is undefined
    The constructor MenuItem(String, ImageIcon) is undefined

    at minecraft.status.checker.Interface.mainInterface(Interface.java:23)
    at minecraft.status.checker.MainClass.main(MainClass.java:12)
</code></pre>