Java Code Examples for javax.swing.JMenuBar#remove()
The following examples show how to use
javax.swing.JMenuBar#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WindowMenu.java From pumpernickel with MIT License | 6 votes |
/** * On Mac often the menus won't really update without this hack-ish twist: * remove the menu and re-add it. Voila! It's both unnecessary and crucial * at the same time. * * @param f * the frame whose menubar you need to update. * @param menu * the menu you need to update. */ static void fixMenuBar(JFrame f, JMenu menu) { JMenuBar mb = f.getJMenuBar(); if (mb != null) { JMenu[] menus = new JMenu[mb.getMenuCount()]; for (int a = 0; a < menus.length; a++) { menus[a] = mb.getMenu(a); } boolean found = false; List<JMenu> menusToAdd = new ArrayList<>(); for (int a = 0; a < menus.length; a++) { if (menus[a] == menu) found = true; if (found) { mb.remove(menus[a]); menusToAdd.add(menus[a]); } } for (JMenu menuToAdd : menusToAdd) { mb.add(menuToAdd); } } }
Example 2
Source File: OSPFrame.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Removes a menu with the given name from the menu bar and returns the removed item. * Returns null if menu item does not exist. * * @param menuName String * @return JMenu */ public JMenu removeMenu(String menuName) { JMenuBar menuBar = getJMenuBar(); if(menuBar==null) { return null; } menuName = menuName.trim(); JMenu menu = null; for(int i = 0; i<menuBar.getMenuCount(); i++) { JMenu next = menuBar.getMenu(i); if(next.getText().trim().equals(menuName)) { menu = next; menuBar.remove(i); break; } } return menu; }
Example 3
Source File: ConfigMenu.java From log-requests-to-sqlite with GNU General Public License v3.0 | 5 votes |
/** * Remove the menu from BURP menu bar. * * @see "https://github.com/PortSwigger/param-miner/blob/master/src/burp/Utilities.java" */ @Override public void extensionUnloaded() { JFrame burpFrame = ConfigMenu.getBurpFrame(); if (burpFrame != null && this.cfgMenu != null) { JMenuBar jMenuBar = burpFrame.getJMenuBar(); jMenuBar.remove(this.cfgMenu); jMenuBar.repaint(); this.trace.writeLog("Configuration menu removed."); } else { this.trace.writeLog("Cannot remove the configuration menu (ref on the BURP frame is null)."); } }
Example 4
Source File: MainFrameClassicMenu.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
@Override public void finishMenu(String path) { path = mapping(path); if (path.equals("_") || path.startsWith("_/")) { return; } if (!menuElements.containsKey(path)) { throw new IllegalArgumentException("Invalid menu: " + path); } if (path.startsWith("/file/recent")) { return; } MenuElement me = menuElements.get(path); if (me instanceof JMenu) { JMenu jm = (JMenu) me; if (jm.getMenuComponentCount() == 1) { String parentPath = path.contains("/") ? path.substring(0, path.lastIndexOf('/')) : ""; MenuElement parMe = menuElements.get(parentPath); JMenuItem mi = (JMenuItem) jm.getMenuComponent(0); jm.remove(mi); if (parMe instanceof JMenu) { JMenu parMenu = (JMenu) parMe; parMenu.remove(jm); parMenu.add(mi); } else if (parMe instanceof JMenuBar) { JMenuBar parMenuBar = (JMenuBar) parMe; parMenuBar.remove(jm); parMenuBar.add(mi); } } } }