0

I have a tray icon added to system tray. A popup menu is associated with the tray icon. According to the image set on tray icon, the popup menu should be displayed. Ex: On right click of gray image on TrayIcon, the active menu should come; and for any other images, the deactivate menu should come.

It is working as expected in most of the systems, but in some systems the pop up menu is not coming as expected sporadically. For example: On right click of gray image on TrayIcon getting deactive menu instead of activate menu. I guess the popup menu is not getting refreshed if we keep on right click on the tray icon. Is there any way to refresh the popup menu in tray icon?

I am using trayIcon.setPopupMenu(popupMenu);

Any help would be greatly appreciated.

public void handleRightClick(MouseEvent event)throws Exception{

    LOGGER.info("Mouse right click happens on tray icon..");
    CustomTrayIcon cTray = new CustomTrayIcon();
    CIcon icon = new CIcon();
    PopupMenu popupMenu=null;
    String popupName = null;

    if (trayIcon != null) {
        if (trayIcon.getImage() == icon.createGrayIcon()) {                 
            popupMenu = cTray.getActivatePopupMenu();
            if(trayIcon.getPopupMenu() == null){
                popupName = "Name Not Set";
            }
            else{
                popupName = trayIcon.getPopupMenu().getName();
            }
            LOGGER.info("Before setting activate Popup menu into tray icon. Name:" +  popupName);
            popupMenu.setName("Active Menu");
            trayIcon.setPopupMenu(popupMenu);
            LOGGER.info("After setting activate Popup menu into tray icon. Name: " + trayIcon.getPopupMenu().getName());
        } else {            
            popupMenu = cTray.getDeactivatePopupMenu();
            if(trayIcon.getPopupMenu() == null){
                popupName = "Name Not Set";
            }
            else{
                popupName = trayIcon.getPopupMenu().getName();
            }

            LOGGER.info("Before setting deactivate Popup menu into tray icon. Name:" + popupName);  
            popupMenu.setName("Deactive Menu");
            trayIcon.setPopupMenu(popupMenu);               
            LOGGER.info("After setting deactivate Popup menu into tray icon. Name: " + trayIcon.getPopupMenu().getName());
        }           
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Aseet
  • 1
  • 1
  • 1
    For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Jan 06 '15 at 08:19
  • HI Francois Borgies, Please find the sample code updated in the summary. The trayIcon in the example is an object of TrayIcon and initialised while adding the trayicon into system tray. – Aseet Jan 06 '15 at 09:37

0 Answers0