title: Open popup(Menu) on task tray icon with left click using java
body: <p>I am working on task tray Icon in java, I like to open a popup Menu using left click same popup Menu as I open on right click, and please help me with a quick response.</p>
  
  <p>Thanks in advance...</p>
  
  <p>here is the code working for right click need to show same popup on left click... 
  don't forget to place any image @ "src/img" folder with name "titleImg.jpg"</p>
  
  <p>Just run this... it is a working example but i have to show same popup using left click</p>
  
  <p>i have checked the Mouse Listener, it listen the left click on tray icon but how to show popup menu using that ???</p>
  
  <pre><code>    package com.abc.dao;
  
  import java.awt.AWTException;
  import java.awt.CheckboxMenuItem;
  import java.awt.Menu;
  import java.awt.MenuItem;
  import java.awt.PopupMenu;
  import java.awt.SystemTray;
  import java.awt.Toolkit;
  import java.awt.TrayIcon;
  
  public class MyTaskTray {
      public static void main(String arg[]){
  
          //Check the SystemTray is supported
          if (!SystemTray.isSupported()) {
              System.out.println("SystemTray is not supported");
              return;
          }
          final PopupMenu popup = new PopupMenu();
          final TrayIcon trayIcon =
                  new TrayIcon(Toolkit.getDefaultToolkit().getImage(new java.io.File("").getAbsolutePath()+"/bin/img/titleImg.jpg"), "Library Drop");
          final SystemTray tray = SystemTray.getSystemTray();
  
          // Create a pop-up menu components
          MenuItem aboutItem = new MenuItem("About");
          CheckboxMenuItem cb1 = new CheckboxMenuItem("Set auto size");
          CheckboxMenuItem cb2 = new CheckboxMenuItem("Set tooltip");
          Menu displayMenu = new Menu("Display");
          MenuItem errorItem = new MenuItem("Error");
          MenuItem warningItem = new MenuItem("Warning");
          MenuItem infoItem = new MenuItem("Info");
          MenuItem noneItem = new MenuItem("None");
          MenuItem exitItem = new MenuItem("Exit");
  
          //Add components to pop-up menu
          popup.add(aboutItem);
          popup.addSeparator();
          popup.add(cb1);
          popup.add(cb2);
          popup.addSeparator();
          popup.add(displayMenu);
          displayMenu.add(errorItem);
          displayMenu.add(warningItem);
          displayMenu.add(infoItem);
          displayMenu.add(noneItem);
          popup.add(exitItem);
  
          trayIcon.setPopupMenu(popup);
  
          try {
              tray.add(trayIcon);
          } catch (AWTException e) {
              System.out.println("TrayIcon could not be added.");
          }
  
      }
  }
  </code></pre>