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 (5627L/36K).

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) null on exception {
  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  old transpilations   

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

No comments. add comment

Snippet ID: #1003656
Snippet name: installTrayIcon - takes image ID and menu item params
Eternal ID of this version: #1003656/13
Text MD5: bed8cfdacab9491d8df5fad1f43282d6
Transpilation MD5: 5e39deee8fcbf87c02fcb41d95687604
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-05-20 17:24:48
Source code size: 1284 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 475 / 546
Version history: 12 change(s)
Referenced in: [show references]

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