Libraryless. Click here for Pure Java version (9923L/55K).
sclass PopupMenuMaker { settable bool allowScrolling = true; // ignored when using existingMenu settable MouseEvent event; settable PtInComponent ptInComponent; // if different from event settable IVF1<JPopupMenu> fillMenu; settable JPopupMenu existingMenu; settable bool addSeparator = true; // add separator if existing meun JPopupMenu menu; *() {} *(MouseEvent *event, IVF1<JPopupMenu> *fillMenu) {} public void run() swing { if (existingMenu != null) { fix(); 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); } ptInComponent if null = ptInComponentFromEvent(event); if (hasParentOfType JPopupMenu(ptInComponent.component)) { // component is in a menu itself. TODO: better positioning // Also this doesn't actually seem to work... menu.setInvoker(ptInComponent.component); menu.setVisible(true); } else menu.show(ptInComponent.component, ptInComponent.p.x, ptInComponent.p.y); } } svoid fix { JPopupMenu.setDefaultLightWeightPopupEnabled(false); } }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034567 |
Snippet name: | PopupMenuMaker |
Eternal ID of this version: | #1034567/16 |
Text MD5: | a7f8d8f73562ae4ba067ee790510a36c |
Transpilation MD5: | bc3b310088f273053cf5a9dc2223af3a |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-20 23:24:50 |
Source code size: | 1907 bytes / 57 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 207 / 370 |
Version history: | 15 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |