Libraryless. Click here for Pure Java version (64L/1K).
1 | static class PopupMenuHelper extends MouseAdapter { |
2 | JPopupMenu menu; |
3 | Point point; |
4 | |
5 | /** override me */ |
6 | swappable void fillMenu() { |
7 | } |
8 | |
9 | public void mousePressed(MouseEvent e) { |
10 | displayMenu(e); |
11 | } |
12 | |
13 | public void mouseReleased(MouseEvent e) { |
14 | displayMenu(e); |
15 | } |
16 | |
17 | private void displayMenu(MouseEvent e) { |
18 | boolean popupTrigger = e.isPopupTrigger(); |
19 | if (popupTrigger) { |
20 | JPopupMenu menu = new JPopupMenu(); |
21 | int count = menu.getComponentCount(); |
22 | this.menu = menu; |
23 | this.point = e.getPoint(); |
24 | fillMenu(); |
25 | this.menu = null; |
26 | if (menu.getComponentCount() != count) |
27 | menu.show(e.getComponent(), e.getX(), e.getY()); |
28 | } |
29 | } |
30 | |
31 | public void install(JComponent component) { |
32 | component.addMouseListener(this); |
33 | } |
34 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1000839 |
Snippet name: | PopupMenuHelper |
Eternal ID of this version: | #1000839/2 |
Text MD5: | 57785762592ba949f9f1c922abc65e0e |
Transpilation MD5: | 6a4e2489a9fee90cc0ee7bee430a383e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-25 20:20:44 |
Source code size: | 817 bytes / 34 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 729 / 2939 |
Version history: | 1 change(s) |
Referenced in: | [show references] |