sclass PopupMenuMaker { settable bool allowScrolling = true; // ignored when using existingMenu settable MouseEvent event; settable IVF1 fillMenu; settable JPopupMenu existingMenu; settable bool addSeparator = true; // add separator if existing meun JPopupMenu menu; *() {} *(MouseEvent *event, IVF1 *fillMenu) {} public void run() swing { if (existingMenu != null) { var menu = existingMenu; int emptyCount = menu.getComponentCount(); if (addSeparator) menu.addSeparator(); int emptyCount2 = menu.getComponentCount(); fillMenu?.get(menu); if (menu.getComponentCount() == emptyCount2) truncateContainer(menu, emptyCount); //printVars("Extended popup menu", +emptyCount, +emptyCount2, n := menu.getComponentCount()); packWindow(menu); //revalidate(menu); } else { new JPopupMenu menu; int emptyCount = menu.getComponentCount(); fillMenu?.get(menu); if (menu.getComponentCount() == emptyCount) ret; if (allowScrolling) { menu = new JPopupMenu; JMenuScroller scroller = JMenuScroller.setScrollerFor(menu); scroller.fillMenu = toVF1(fillMenu); } if (hasParentOfType JPopupMenu(event.getComponent())) { // component is in a menu itself. TODO: better positioning menu.setInvoker(event.getComponent()); menu.setVisible(true); } else menu.show(event.getComponent(), event.getX(), event.getY()); } } }