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

15
LINES

< > BotCompany Repo | #1019927 // makePopupMenuConditional

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

Libraryless. Click here for Pure Java version (5566L/31K).

1  
// show popup menu on right click only when a condition is met
2  
svoid makePopupMenuConditional(JComponent c, F0<Bool> condition) {
3  
  if (c != null && condition != null) swing {
4  
    componentPopupMenu_Adapter adapter = firstInstanceOf(c.getMouseListeners(), componentPopupMenu_Adapter);
5  
    c.removeMouseListener(adapter);
6  
    c.addMouseListener(new MouseAdapter {
7  
      public void mousePressed(MouseEvent e) {
8  
        if (!callF(condition)) adapter.mousePressed(e);
9  
      }
10  
      public void mouseReleased(MouseEvent e) {
11  
        if (!callF(condition)) adapter.mouseReleased(e);
12  
      }
13  
    });
14  
  }
15  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019927
Snippet name: makePopupMenuConditional
Eternal ID of this version: #1019927/4
Text MD5: 460281e194aeac348f2a0383b30da2c2
Transpilation MD5: 2b3e15bdb92d9cc90d7cc298a1fa7932
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-24 16:49:32
Source code size: 614 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 352 / 459
Version history: 3 change(s)
Referenced in: [show references]