List of usage examples for javax.swing JMenuBar remove
public void remove(int index)
From source file:AddingRemovingJMenu.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*ww w . j a v a 2 s . c om*/ JMenu editMenu = new JMenu("Edit"); menuBar.add(editMenu); menuBar.remove(0); menuBar.revalidate(); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:org.kepler.gui.MenuMapper.java
public void init() { if (_tableauFrameInstance == null) { log.error(//from w ww .jav a 2 s . c om "MenuMapper cannot proceed, due to one or more NULL values:" + "\nptiiMenubar = " + _ptiiMenubar + "\ntableauFrameInstance = " + _tableauFrameInstance + "\ndefaulting to PTII menus"); return; } // First, we need to make sure PTII has finished constructing its menus. // Those menus are created and assembled in a thread that is started in // the // pack() method of ptolemy.gui.Top. As that thread finishes, it adds // the // new ptii JMenuBar to the frame - so we test for that here, and don't // proceed until the frame has the new JMenuBar added // For safety, so we don't have an infinite loop, we also set a safety // counter: // maxWaitMS is the longest the app waits for the ptii // menus to be added, before it continues anyway. final int maxWaitMS = 500; // sleepTimeMS is the amount of time it sleeps per loop: final int sleepTimeMS = 5; // //// final int maxLoops = maxWaitMS / sleepTimeMS; int safetyCounter = 0; while (safetyCounter++ < maxLoops && !_tableauFrameInstance.isMenuPopulated()) { if (isDebugging) { log.debug("Waiting for PTII menus to be created... " + safetyCounter); } try { Thread.sleep(sleepTimeMS); } catch (Exception e) { // ignore } } JMenuBar _keplerMenubar = null; if (_ptiiMenubar == null) { _ptiiMenubar = _tableauFrameInstance.getJMenuBar(); } if (_ptiiMenubar != null) { // gets here if a PTII menubar has been added to frame... // 1) Now PTII has finished constructing its menus, get all // menu items and put them in a Map for easier access later... _ptiiMenuActionsMap = getPTIIMenuActionsMap(); Map<String, Action> ptiiMenuActionsMap = _ptiiMenuActionsMap; // 2) Now we have all the PTII menu items, get the // Kepler-specific menu mappings from the preferences file, // then go thru the Kepler menu mappings and // populate the new menubar with Kepler menus, // creating any new menu items that don't exist yet // this is a Map that will be used to keep track of // what we have added to the menus, and in what order _keplerMenubar = createKeplerMenuBar(ptiiMenuActionsMap); if (_keplerMenubar != null) { // First, look to see if any menus are empty. If // they are, remove the top-level menu from the menubar... // ** NOTE - do these by counting *down* to zero, otherwise the // menus' // indices change dynamically as we remove menus, causing // errors! for (int m = _keplerMenubar.getMenuCount() - 1; m >= 0; m--) { JMenu nextMenu = _keplerMenubar.getMenu(m); if (nextMenu.getMenuComponentCount() < 1) { if (isDebugging) { log.debug("deleting empty menu: " + nextMenu.getText()); } _keplerMenubar.remove(nextMenu); } } // hide the ptii menubar _tableauFrameInstance.hideMenuBar(); // add the new menu bar _tableauFrameInstance.setJMenuBar(_keplerMenubar); } else { log.error("Problem creating Kepler menus - defaulting to PTII menus"); } } else { // gets here if a PTII menubar has *NOT* been added to frame... // Therefore, this frame doesn't have a menubar by default, // so we probably shouldn't add one, for now, at least // hide the ptii menubar (may not be necessary) _tableauFrameInstance.hideMenuBar(); // add the new menu bar (may not be necessary) _tableauFrameInstance.setJMenuBar(null); } }
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Sets the selected pane.// w w w . ja v a 2 s . c om * * @param index The index of the selected tab pane. */ void setSelectedPane(int index) { JMenuBar menuBar = getJMenuBar(); Component[] items = menuBar.getComponents(); Component item; int j = -1; for (int i = 0; i < items.length; i++) { item = items[i]; if (item == zoomGridMenu || item == zoomMenu) j = i; } if (j != -1) menuBar.remove(j); double f; switch (index) { case ImViewer.GRID_INDEX: if (j != -1) menuBar.add(zoomGridMenu, j); f = model.getBrowser().getGridRatio(); setMagnificationStatus(f, ZoomAction.getIndex(f)); break; case ImViewer.PROJECTION_INDEX: case ImViewer.VIEW_INDEX: default: if (j != -1) menuBar.add(zoomMenu, j); f = model.getZoomFactor(); setMagnificationStatus(f, ZoomAction.getIndex(f)); } int oldIndex = model.getTabbedIndex(); model.setTabbedIndex(index); tabs.removeChangeListener(controller); int n = tabs.getTabCount(); Component c; int tabbedIndex; for (int i = 0; i < n; i++) { c = tabs.getComponentAt(i); if (c instanceof ClosableTabbedPaneComponent) { tabbedIndex = ((ClosableTabbedPaneComponent) c).getIndex(); if (tabbedIndex == index) tabs.setSelectedIndex(i); } } tabs.addChangeListener(controller); setLeftStatus(); setPlaneInfoStatus(); model.getBrowser().setSelectedPane(index); setLensVisible(isLensVisible(), oldIndex); maximizeWindow(); }
From source file:org.parosproxy.paros.extension.ExtensionLoader.java
private void removeMenuHelper(JMenuBar menuBar, List<JMenuItem> items) { for (JMenuItem item : items) { if (item != null) { menuBar.remove(item); }//from w w w .j a v a2 s .co m } menuBar.revalidate(); }