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

40
LINES

< > BotCompany Repo | #1003656 - installTrayIcon - takes image ID and menu item params

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

Libraryless. Click here for Pure Java version (4813L/33K).

1  
static TrayIcon installTrayIcon(S imageID, S tooltip) {
2  
  ret installTrayIcon(imageID, tooltip, null);
3  
}
4  
5  
// menuItems can also just be a PopupMenu
6  
// also, first of menuItems can be a Runnable for left-click on icon
7  
static TrayIcon installTrayIcon(S imageID, S tooltip, O... menuItems) ctex {
8  
  // convenience parameter swap :-)
9  
10  
  if (!isSnippetID(imageID) && isSnippetID(tooltip)) {
11  
    S s = tooltip;
12  
    tooltip = imageID;
13  
    imageID = s;
14  
  }
15  
  
16  
  ret installTrayIcon(imageIcon(imageID).getImage(), tooltip, menuItems);
17  
}
18  
19  
static TrayIcon installTrayIcon(final Image image, fS tooltip, fO... _menuItems) ctex {
20  
  ret swing(func -> TrayIcon {
21  
    Runnable leftClick = null;
22  
    O[] menuItems = params_unpackList(_menuItems);
23  
    if (l(menuItems) > 0 && menuItems[0] instanceof Runnable) {
24  
      leftClick = (Runnable) menuItems[0];
25  
      menuItems = dropFirst(menuItems);
26  
    }
27  
  
28  
    PopupMenu menu = makePopupMenu(menuItems);
29  
    TrayIcon trayIcon = new TrayIcon(image, tooltip, menu);
30  
    trayIcon.setImageAutoSize(true);
31  
    
32  
    if (leftClick != null) {
33  
      final Runnable _leftClick = leftClick;
34  
      onLeftClick(trayIcon, _leftClick);
35  
    }
36  
    
37  
    SystemTray.getSystemTray().add(trayIcon);
38  
    ret trayIcon;
39  
  });
40  
}

download  show line numbers  debug dex   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1003656
Snippet name: installTrayIcon - takes image ID and menu item params
Eternal ID of this version: #1003656/11
Text MD5: bb2bef6ab5daa0d0fe98c2b96b433153
Transpilation MD5: f36b1ee8f734f54ad62113c127e3e5bc
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-27 14:32:53
Source code size: 1271 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 438 / 487
Version history: 10 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1003656 & http://1003656.tinybrain.de