Libraryless. Click here for Pure Java version (3758L/25K).
1 | // menuParams: text, Runnable, ... |
2 | // also: position := 'left/'center/'right |
3 | static JButton jPopDownButton(S text, fO... menuParams) { |
4 | ret jbutton((empty(text) ? "" : text + " ") + unicode_downPointingTriangle(), r { |
5 | new JPopupMenu menu; |
6 | int emptyCount = menu.getComponentCount(); |
7 | S position = cast optPar_ignoreOddLength position(menuParams); // TODO: this fails when you include a separator without a following null |
8 | fillJPopupMenu(menu, paramsWithout(menuParams, 'position)); |
9 | if (menu.getComponentCount() != emptyCount) { |
10 | JButton btn = heldInstance(JButton); |
11 | int x = 0; |
12 | if (eq(position, 'center)) x = (btn.getWidth()-getPreferredWidth(menu))/2; |
13 | else if (eq(position, 'right)) x = btn.getWidth()-getPreferredWidth(menu); |
14 | menu.show(btn, x, btn.getHeight()); |
15 | } |
16 | }); |
17 | } |
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1020102 |
Snippet name: | jPopDownButton - button that shows a popup menu. Automatically adds a small triangle to the button text |
Eternal ID of this version: | #1020102/7 |
Text MD5: | 48a5678814441fbd143991194b0e42d6 |
Transpilation MD5: | 8a383792fe2dfda76387b50444e47660 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-11 19:00:50 |
Source code size: | 839 bytes / 17 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 383 / 477 |
Version history: | 6 change(s) |
Referenced in: | [show references] |