sclass componentPopupMenu_Maker { new L menuMakers; } static Map componentPopupMenu_map = new WeakHashMap; static new ThreadLocal componentPopupMenu_mouseEvent; // menuMaker = voidfunc(JPopupMenu) static void componentPopupMenu(final JComponent component, fO menuMaker) { awtIfNecessary { componentPopupMenu_Maker maker = componentPopupMenu_map.get(component); if (maker == null) { componentPopupMenu_map.put(component, maker = new componentPopupMenu_Maker); final componentPopupMenu_Maker _maker = maker; component.addMouseListener(new MouseAdapter { public void mousePressed(MouseEvent e) { displayMenu(e); } public void mouseReleased(MouseEvent e) { displayMenu(e); } void displayMenu(MouseEvent e) { if (e.isPopupTrigger()) { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); componentPopupMenu_mouseEvent.set(e); for (O menuMaker : _maker.menuMakers) pcallF(menuMaker, menu); // show menu if any items in it if (menu.getComponentCount() != emptyCount) menu.show(e.getComponent(), e.getX(), e.getY()); } } }); } maker.menuMakers.add(menuMaker); } }