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).

static TrayIcon installTrayIcon(S imageID, S tooltip) {
  ret installTrayIcon(imageID, tooltip, null);
}

// menuItems can also just be a PopupMenu
// also, first of menuItems can be a Runnable for left-click on icon
static TrayIcon installTrayIcon(S imageID, S tooltip, O... menuItems) ctex {
  // convenience parameter swap :-)

  if (!isSnippetID(imageID) && isSnippetID(tooltip)) {
    S s = tooltip;
    tooltip = imageID;
    imageID = s;
  }
  
  ret installTrayIcon(imageIcon(imageID).getImage(), tooltip, menuItems);
}

static TrayIcon installTrayIcon(final Image image, fS tooltip, fO... _menuItems) ctex {
  ret swing(func -> TrayIcon {
    Runnable leftClick = null;
    O[] menuItems = params_unpackList(_menuItems);
    if (l(menuItems) > 0 && menuItems[0] instanceof Runnable) {
      leftClick = (Runnable) menuItems[0];
      menuItems = dropFirst(menuItems);
    }
  
    PopupMenu menu = makePopupMenu(menuItems);
    TrayIcon trayIcon = new TrayIcon(image, tooltip, menu);
    trayIcon.setImageAutoSize(true);
    
    if (leftClick != null) {
      final Runnable _leftClick = leftClick;
      onLeftClick(trayIcon, _leftClick);
    }
    
    SystemTray.getSystemTray().add(trayIcon);
    ret trayIcon;
  });
}

download  show line numbers  debug dex   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, 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: 410 / 452
Version history: 10 change(s)
Referenced in: [show references]

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