Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #1034224 // JPopDownButton - generalized jPopDownButton

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (10394L/59K).

1  
sclass JPopDownButton > JButton {
2  
  S menuPosition = "left"; // or "center" or "right"
3  
  
4  
  *() { this(""); }
5  
  *(S text) {
6  
    super(joinNemptiesWithSpace(text, unicode_downPointingTriangle()));
7  
    main addActionListener(this, r openMenu);
8  
  }
9  
  
10  
  *(IVF1<JPopupMenu> *fillMenu) { this(); }
11  
  
12  
  selfType content(O... items) {
13  
    onFillingMenu(menu -> fillJPopupMenu(menu, items));
14  
    this;
15  
  }
16  
  
17  
  event fillingMenu(JPopupMenu menu);
18  
  
19  
  swappable void fillMenu(JPopupMenu menu) {
20  
    fillingMenu(menu);
21  
  }
22  
  
23  
  void openMenu {
24  
    new JPopupMenu menu;
25  
    int emptyCount = menu.getComponentCount();
26  
    fillMenu(menu);
27  
    if (menu.getComponentCount() == emptyCount) ret;
28  
    
29  
    int x = 0;
30  
    if (eq(menuPosition, "center")) x = (getWidth()-getPreferredWidth(menu))/2;
31  
    else if (eq(menuPosition, "right")) x = getWidth()-getPreferredWidth(menu);
32  
    menu.show(this, x, getHeight());
33  
  }
34  
  
35  
  visual this;
36  
}

Author comment

Began life as a copy of #1020102

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034224
Snippet name: JPopDownButton - generalized jPopDownButton
Eternal ID of this version: #1034224/8
Text MD5: 8c865c9c059b240681bf792ce6b76162
Transpilation MD5: d5975120704fc219aee17db24ddf11ed
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-16 16:48:24
Source code size: 956 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 154 / 300
Version history: 7 change(s)
Referenced in: [show references]