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

27
LINES

< > BotCompany Repo | #1004034 // addMenu - replaces whole menu if it is there

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

Libraryless. Click here for Pure Java version (3335L/22K).

static new ThreadLocal<Bool> addMenu_addIfEmpty; // defaults to true

static JMenu addMenu(final Component c, fS menuName, fO... items) {
  final RootPaneContainer frame = getPossiblyInternalFrame(c);
  ret (JMenu) swing(func {
    JMenuBar bar = addMenuBar((Component) frame);
    Pair<S, Int> p = jmenu_autoMnemonic(menuName);
    JMenu menu = getMenuNamed(bar, p.a);
    bool isNew = menu == null;
    ifdef addMenu_debug
      print("addMenu " + menuName + " " + isNew);
    endifdef
    if (isNew)
      menu = new JMenu(p.a);
    else
      menu.removeAll();
    menu.setMnemonic(p.b);
    fillJMenu(menu, items);
    if (isNew) {
      if (!isFalse(addMenu_addIfEmpty!) || menuItemCount(menu) > 0) {
        bar.add(menu);
        revalidate((Component) frame);
      }
    }
    ret menu;
  });
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004034
Snippet name: addMenu - replaces whole menu if it is there
Eternal ID of this version: #1004034/14
Text MD5: 4e80e993d32ffbc4cdc8d780b53384f5
Transpilation MD5: 03873f97a679ad7f161da0e010cc3336
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-30 14:19:02
Source code size: 830 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 736 / 785
Version history: 13 change(s)
Referenced in: [show references]