Java Code Examples for javax.swing.JMenu

The following examples show how to use javax.swing.JMenu. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
protected JMenuBar createMenuBar()
  {
    final JMenuBar menuBar = new JMenuBar();

//Set up the lone menu.
    final JMenu menu = new JMenu("Document");
    menu.setMnemonic(KeyEvent.VK_D);
    menuBar.add(menu);

    menu.add(new JMenuItem(new NewFrameAction()));
    menu.add(new JMenuItem(getPreviewAction()));
    menu.addSeparator();
    menu.add(new JMenuItem(getCloseAction()));

    final JMenu helpmenu = new JMenu("Help");
    helpmenu.setMnemonic(KeyEvent.VK_H);
    helpmenu.add(new JMenuItem(getAboutAction()));
    return menuBar;
  }
 
Example 2
Source Project: netcdf-java   Source File: PLAF.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 */
private void addToMenu(String name, String className, JMenu menu) {
  logger.debug("PLAF LookAndFeelInfo  {}", className);
  boolean isSupported = true;
  try {
    Class cl = Class.forName(className);
    LookAndFeel lf = (LookAndFeel) cl.newInstance();
    if (!lf.isSupportedLookAndFeel()) {
      isSupported = false;
    }
  } catch (Throwable t) {
    isSupported = false;
  }

  AbstractAction act = new PLAFAction(name, className);
  JMenuItem mi = menu.add(act);
  if (!isSupported) {
    mi.setEnabled(false);
  }
}
 
Example 3
Source Project: jaamsim   Source File: GUIFrame.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the Help menu in the Control Panel's menu bar.
 */
private void initializeHelpMenu() {

	// Help menu creation
	helpMenu = new JMenu( "Help" );
	helpMenu.setMnemonic(KeyEvent.VK_H);

	// 1) "About" menu item
	JMenuItem aboutMenu = new JMenuItem( "About" );
	aboutMenu.setMnemonic(KeyEvent.VK_A);
	aboutMenu.addActionListener( new ActionListener() {

		@Override
		public void actionPerformed( ActionEvent event ) {
			AboutBox.instance().setVisible(true);
		}
	} );
	helpMenu.add( aboutMenu );
}
 
Example 4
Source Project: amidst   Source File: AmidstMenuBuilder.java    License: GNU General Public License v3.0 6 votes vote down vote up
private JMenu create_Settings() {
	JMenu result = new JMenu("Settings");
	result.setMnemonic(KeyEvent.VK_S);
	result.add(create_Settings_DefaultWorldType());
	if (biomeProfileDirectory.isValid()) {
		result.add(create_Settings_BiomeProfile());
	}
	result.addSeparator();
	// @formatter:off
	Menus.checkbox(result, settings.smoothScrolling,      "Smooth Scrolling");
	Menus.checkbox(result, settings.fragmentFading,       "Fragment Fading");
	Menus.checkbox(result, settings.maxZoom,              "Restrict Maximum Zoom");
	Menus.checkbox(result, settings.showFPS,              "Show Framerate & CPU");
	Menus.checkbox(result, settings.showScale,            "Show Scale");
	Menus.checkbox(result, settings.showDebug,            "Show Debug Information");
	// @formatter:on
	result.addSeparator();
	result.add(create_Settings_LookAndFeel());
	return result;
}
 
Example 5
Source Project: netbeans   Source File: LanguagesGenerateFoldPopupAction.java    License: Apache License 2.0 6 votes vote down vote up
private void addFoldTypes (JTextComponent target, JMenu menu, Language language, Set expands) {
    List<Feature> features = language.getFeatureList ().getFeatures (LanguagesFoldManager.FOLD);
    Iterator<Feature> it = features.iterator ();
    while (it.hasNext ()) {
        Feature fold = it.next ();
        String expand = LocalizationSupport.localize (language, (String) fold.getValue ("expand_type_action_name"));
        if (expand == null) continue;
        if (expands.contains (expand))
            continue;
        expands.add (expand);
        String collapse = LocalizationSupport.localize (language, (String) fold.getValue ("collapse_type_action_name"));
        if (collapse == null) continue;
        addAction (target, menu, EXPAND_PREFIX + expand);
        addAction (target, menu, COLLAPSE_PREFIX + collapse);
        setAddSeparatorBeforeNextAction (true);
    }
}
 
Example 6
Source Project: pumpernickel   Source File: WindowMenu.java    License: MIT License 6 votes vote down vote up
/**
 * 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 7
Source Project: JglTF   Source File: GltfBrowserApplication.java    License: MIT License 6 votes vote down vote up
/**
 * Create the file menu
 * 
 * @return The file menu
 */
private JMenu createFileMenu()
{
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(new JMenuItem(openFileAction));
    fileMenu.add(new JMenuItem(openUriAction));
    fileMenu.add(new JSeparator());

    fileMenu.add(recentUrisMenu.getMenu());
    fileMenu.add(new JSeparator());

    fileMenu.add(new JMenuItem(importObjFileAction));
    fileMenu.add(new JSeparator());
    
    fileMenu.add(new JMenuItem(saveAsAction));
    fileMenu.add(new JMenuItem(saveAsBinaryAction));
    fileMenu.add(new JMenuItem(saveAsEmbeddedAction));
    fileMenu.add(new JSeparator());
    fileMenu.add(new JMenuItem(exitAction));
    return fileMenu;
}
 
Example 8
Source Project: netbeans   Source File: DynaMenuModelTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test of checkSubmenu method, of class org.openide.awt.DynaMenuModel.
 */
public void testCheckSubmenu() {
    List<Object> cInstances = new ArrayList<Object>();
    cInstances.add(new Act1());
    cInstances.add(new Act2());
    JMenu m = new JMenu();
    DynaMenuModel instance = new DynaMenuModel();
    
    instance.loadSubmenu(cInstances, m, false, Collections.<Object,FileObject>emptyMap());
    instance.checkSubmenu(m);
    
    Component[] comps = m.getPopupMenu().getComponents();
    assertEquals("0", ((JMenuItem)comps[0]).getText());
    assertEquals("1x", ((JMenuItem)comps[1]).getText());
    assertEquals("2x", ((JMenuItem)comps[2]).getText());
    
}
 
Example 9
Source Project: dragonwell8_jdk   Source File: bug8031573.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JMenuBar bar = new JMenuBar();
                JMenu menu = new JMenu("Menu");
                JCheckBoxMenuItem checkBoxMenuItem
                        = new JCheckBoxMenuItem("JCheckBoxMenuItem");
                checkBoxMenuItem.setSelected(true);
                menu.add(checkBoxMenuItem);
                bar.add(menu);
                setJMenuBar(bar);
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source Project: wpcleaner   Source File: AbstractMenuCreator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Add an item to a menu.
 * 
 * @param menu Menu.
 * @param page Page.
 * @param title Element title (if null, the page title will be used).
 * @param asIs True if the message should be used as is (no mnemonic).
 * @param action Action.
 * @param accelerator Accelerator.
 * @return Number of items added.
 */
public int addItem(
    JMenu menu, Page page, String title, boolean asIs,
    ActionListener action, KeyStroke accelerator) {
  if (menu == null) {
    return 0;
  }
  if ((title == null) && ((page == null) || (page.getTitle() == null))) {
    return 0;
  }
  JMenuItem menuItem = Utilities.createJMenuItem(title != null ? title : page.getTitle(), asIs);
  if (page != null) {
    updateFont(menuItem, page);
  }
  if (action != null) {
    menuItem.addActionListener(action);
  }
  if (accelerator != null) {
    menuItem.setAccelerator(accelerator);
  }
  menu.add(menuItem);
  return 1;
}
 
Example 11
private void init() {
    JMenu setPriority = new JMenu("Set Priority");
    JMenu addProp = new JMenu("Add Property");
    JMenu clearProp = new JMenu("Clear Property");
    JMenu deleteProp = new JMenu("Remove Property");

    setPriority.add(Utils.createMenuItem("Set Priority to Page", MobileORTable.this));
    setPriority.add(Utils.createMenuItem("Set Priority to All", MobileORTable.this));
    setPriority.add(Utils.createMenuItem("Set Priority to Selected", MobileORTable.this));
    add(setPriority);
    clearProp.add(Utils.createMenuItem("Clear from Page", MobileORTable.this));
    clearProp.add(Utils.createMenuItem("Clear from All", MobileORTable.this));
    clearProp.add(Utils.createMenuItem("Clear from Selected", MobileORTable.this));
    add(clearProp);
    deleteProp.add(Utils.createMenuItem("Remove from Page", MobileORTable.this));
    deleteProp.add(Utils.createMenuItem("Remove from All", MobileORTable.this));
    deleteProp.add(Utils.createMenuItem("Remove from Selected", MobileORTable.this));
    add(deleteProp);
    addProp.add(Utils.createMenuItem("Add to Page", MobileORTable.this));
    addProp.add(Utils.createMenuItem("Add to All", MobileORTable.this));
    addProp.add(Utils.createMenuItem("Add to Selected", MobileORTable.this));
    add(addProp);
}
 
Example 12
Source Project: android-screen-monitor   Source File: MainFrame.java    License: Apache License 2.0 6 votes vote down vote up
private void addRadioButtonMenuItemZoom(
		JMenu menuZoom, ButtonGroup buttonGroup,
		final double zoom, String caption, int nemonic,
		double currentZoom) {
	JRadioButtonMenuItem radioButtonMenuItemZoom = new JRadioButtonMenuItem(caption);
	if (nemonic != -1) {
		radioButtonMenuItemZoom.setMnemonic(nemonic);
	}
	radioButtonMenuItemZoom.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			setZoom(zoom);
		}
	});
	if (currentZoom == zoom) {
		radioButtonMenuItemZoom.setSelected(true);
	}
	buttonGroup.add(radioButtonMenuItemZoom);
	menuZoom.add(radioButtonMenuItemZoom);
}
 
Example 13
Source Project: ChatGameFontificator   Source File: ComboMenuBar.java    License: The Unlicense 6 votes vote down vote up
private void setup(final JMenu menu)
{
    Color color = UIManager.getColor("Menu.selectionBackground");
    UIManager.put("Menu.selectionBackground", UIManager.getColor("Menu.background"));
    menu.updateUI();
    UIManager.put("Menu.selectionBackground", color);

    ActionListener listener = new ActionListener()
    {
        @Override
        public void actionPerformed(ActionEvent e)
        {
            JMenuItem item = (JMenuItem) e.getSource();
            menu.setText(item.getText());
            menu.requestFocus();
        }
    };
    setListener(menu, listener);

    add(menu);
}
 
Example 14
Source Project: netbeans   Source File: OutputTab.java    License: Apache License 2.0 6 votes vote down vote up
private void addFoldingActionsToPopUpMenu(JPopupMenu menu,
        List<TabAction> activeActions) {
    JMenu submenu = new JMenu(NbBundle.getMessage(
            OutputTab.class, "LBL_OutputFolds"));                   //NOI18N
    for (ACTION a : popUpFoldItems) {
        if (a == null) {
            submenu.addSeparator();
        } else {
            TabAction ta = action(a);
            activeActions.add(ta);
            submenu.add(new JMenuItem(ta));
        }
    }
    menu.addSeparator();
    menu.add(submenu);
}
 
Example 15
private void createMenu(String selection) {
    menu = new JMenu();
    menu.setText("Transmitting Hardware");
    menu.setToolTipText("Allows direct selection of transmitting hardware");
    buttonGroup = new ButtonGroup();
    table.entrySet().stream().map((kvp) -> {
        String name = kvp.getKey();
        final ISendingHardware<?> hardware = kvp.getValue();
        JRadioButton menuItem = new JRadioButton(name);
        menuItem.setSelected(name.equals(selection));
        //portRadioButtons[i] = menuItem;
        menuItem.addActionListener((java.awt.event.ActionEvent evt) -> {
            try {
                select(hardware);
            } catch (HarcHardwareException ex) {
                guiUtils.error(ex);
            }
        });
        return menuItem;
    }).map((menuItem) -> {
        buttonGroup.add(menuItem);
        return menuItem;
    }).forEachOrdered((menuItem) -> {
        menu.add(menuItem);
    });
}
 
Example 16
Source Project: pcgen   Source File: PCGenMenuBar.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private JMenu createSourcesMenu()
{
	JMenu menu = new JMenu();
	menu.setText(LanguageBundle.getString("in_mnuSources"));
	menu.setToolTipText(LanguageBundle.getString("in_mnuSourcesTip"));
	menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_LOAD_SELECT_COMMAND)));
	menu.addSeparator();
	menu.add(new QuickSourceMenu());
	menu.addSeparator();
	menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_RELOAD_COMMAND)));
	menu.add(new JMenuItem(actionMap.get(PCGenActionMap.SOURCES_UNLOAD_COMMAND)));
	menu.addSeparator();
	menu.add(actionMap.get(PCGenActionMap.INSTALL_DATA_COMMAND));

	return menu;
}
 
Example 17
Source Project: libGDX-Path-Editor   Source File: EditorRootPane.java    License: Apache License 2.0 5 votes vote down vote up
private JMenu createProjectMenu() {
	JMenu menu = new JMenu(MenuConsts.project);
	
	newProjectItem = new JMenuItem(MenuConsts.newProject);
	newProjectItem.addActionListener(menuHandler);
	newProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_newProject)));
	menu.add(newProjectItem);
	
	openProjectItem = new JMenuItem(MenuConsts.openProject);
	openProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_openProject)));
	openProjectItem.addActionListener(menuHandler);
	menu.add(openProjectItem);
	
	saveProjectItem = new JMenuItem(MenuConsts.saveProhect);
	saveProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_saveProject)));
	saveProjectItem.addActionListener(menuHandler);
	menu.add(saveProjectItem);
	
	closeProjectItem = new JMenuItem(MenuConsts.closeProject);
	closeProjectItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_closeProject)));
	closeProjectItem.addActionListener(menuHandler);
	menu.add(closeProjectItem);
	
	menu.add(new JSeparator());
	
	JMenuItem exitItem = new JMenuItem(MenuConsts.exit);
	exitItem.setIcon(new ImageIcon(this.getClass().getResource(ResourcesConsts.ic_menu_exit)));
	exitItem.addActionListener(menuHandler);
	menu.add(exitItem);
	
	return menu;
}
 
Example 18
Source Project: Carcassonne   Source File: MainMenuBar.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void buildViewMenu() {
    slider = new ZoomSlider(mainUI);
    JMenu menuView = new JMenu(VIEW);
    menuView.add(slider.getZoomIn());
    menuView.add(slider);
    menuView.add(slider.getZoomOut());
    add(menuView);
}
 
Example 19
Source Project: constellation   Source File: NewSchemaGraphAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JComponent[] getMenuPresenters() {
    menu = new JMenu("New Graph");
    for (final SchemaFactory schemaFactory : SchemaFactoryUtilities.getSchemaFactories().values()) {
        if (isValid(schemaFactory)) {
            if (!ICON_CACHE.containsKey(schemaFactory.getName())) {
                ICON_CACHE.put(schemaFactory.getName(), schemaFactory.getIcon().buildIcon(16));
            }
            final JMenuItem item = new JMenuItem(schemaFactory.getLabel(), ICON_CACHE.get(schemaFactory.getName()));
            item.setToolTipText(schemaFactory.getDescription());
            item.setActionCommand(schemaFactory.getName());
            item.addActionListener((final ActionEvent e) -> {
                new Thread() {
                    @Override
                    public void run() {
                        setName(GRAPH_ACTION_THREAD_NAME);
                        final Graph graph = new DualGraph(schemaFactory.createSchema());
                        final WritableGraph wg = graph.getWritableGraphNow("New " + schemaFactory.getName(), false);
                        try {
                            graph.getSchema().newGraph(wg);
                        } finally {
                            wg.commit();
                        }

                        final String graphName = schemaFactory.getLabel().replace(" ", "").toLowerCase();
                        GraphOpener.getDefault().openGraph(graph, graphName);
                    }
                }.start();
            });

            menu.add(item);
        }
    }

    menu.addSeparator();
    recreateTemplateMenuItems();
    return new JComponent[]{menu};
}
 
Example 20
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example 21
Source Project: FCMFrame   Source File: MainFrame.java    License: Apache License 2.0 5 votes vote down vote up
private JMenuItem createCheckBoxMenuItem(JMenu menu, String label, String mnemonic, String accessibleDescription, Action action) {
	JCheckBoxMenuItem mi = (JCheckBoxMenuItem)menu.add(new JCheckBoxMenuItem(label));
	mi.addActionListener(action);
	if(action == null) {
		mi.setEnabled(false);
	}
	return mi;
}
 
Example 22
Source Project: triplea   Source File: ViewMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void addMapSkinsMenu() {
  final JMenu mapSubMenu = new JMenu("Map Skins");
  mapSubMenu.setMnemonic(KeyEvent.VK_K);
  add(mapSubMenu);
  final ButtonGroup mapButtonGroup = new ButtonGroup();
  final Map<String, String> skins = AbstractUiContext.getSkins(frame.getGame().getData());
  mapSubMenu.setEnabled(skins.size() > 1);
  for (final String key : skins.keySet()) {
    final JMenuItem mapMenuItem = new JRadioButtonMenuItem(key);
    mapButtonGroup.add(mapMenuItem);
    mapSubMenu.add(mapMenuItem);
    if (skins.get(key).equals(AbstractUiContext.getMapDir())) {
      mapMenuItem.setSelected(true);
    }
    mapMenuItem.addActionListener(
        e -> {
          try {
            frame.updateMap(skins.get(key));
            if (uiContext.getMapData().getHasRelief()) {
              showMapDetails.setSelected(true);
            }
            showMapDetails.setEnabled(uiContext.getMapData().getHasRelief());
          } catch (final Exception exception) {
            log.log(Level.SEVERE, "Error Changing Map Skin2", exception);
          }
        });
  }
}
 
Example 23
Source Project: netbeans   Source File: Actions.java    License: Apache License 2.0 5 votes vote down vote up
/** Constructor.
*/
public SubMenuBridge(JMenuItem one, JMenu more, Action action, SubMenuModel model, boolean popup) {
    super(one, action, popup);
    single = one;
    multi = more;
    setMenuText(multi, (String)action.getValue(Action.NAME), popup);
    prepareMargins(one, action);
    prepareMargins(more, action);
    currentOnes = new ArrayList<JMenuItem>();
    this.model = model;
}
 
Example 24
Source Project: netbeans   Source File: EditorsAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    JMenu menu = new UpdatingMenu();
    String label = NbBundle.getMessage(EditorsAction.class, "CTL_EditorsAction");
    Actions.setMenuText(menu, label, false);
    return menu;
}
 
Example 25
Source Project: openjdk-8   Source File: WindowsRootPaneUI.java    License: GNU General Public License v2.0 5 votes vote down vote up
void altPressed(KeyEvent ev) {
    MenuSelectionManager msm =
        MenuSelectionManager.defaultManager();
    MenuElement[] path = msm.getSelectedPath();
    if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
        msm.clearSelectedPath();
        menuCanceledOnPress = true;
        ev.consume();
    } else if(path.length > 0) { // We are in ComboBox
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        ev.consume();
    } else {
        menuCanceledOnPress = false;
        WindowsLookAndFeel.setMnemonicHidden(false);
        WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
        JMenuBar mbar = root != null ? root.getJMenuBar() : null;
        if(mbar == null && winAncestor instanceof JFrame) {
            mbar = ((JFrame)winAncestor).getJMenuBar();
        }
        JMenu menu = mbar != null ? mbar.getMenu(0) : null;
        if(menu != null) {
            ev.consume();
        }
    }
}
 
Example 26
Source Project: jdk8u-jdk   Source File: bug8071705.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static JFrame createGUI() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Some menu");
    menuBar.add(menu);

    for (int i = 0; i < 10; i++) {
        menu.add(new JMenuItem("Some menu #" + i));
    }

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(200, 200));
    frame.setJMenuBar(menuBar);
    return frame;
}
 
Example 27
Source Project: gcs   Source File: FileMenuProvider.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public static JMenu createMenu() {
    JMenu menu    = new JMenu(I18n.Text("File"));
    JMenu newMenu = new JMenu(I18n.Text("New Fileā€¦"));
    newMenu.add(new DynamicMenuItem(NewCharacterSheetCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewCharacterTemplateCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewAdvantagesLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewAdvantageModifiersLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewEquipmentLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewEquipmentModifiersLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewNoteLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewSkillsLibraryCommand.INSTANCE));
    newMenu.add(new DynamicMenuItem(NewSpellsLibraryCommand.INSTANCE));
    menu.add(newMenu);
    menu.add(new DynamicMenuItem(OpenCommand.INSTANCE));
    menu.add(new RecentFilesMenu());
    menu.add(new DynamicMenuItem(CloseCommand.INSTANCE));
    menu.addSeparator();
    menu.add(new DynamicMenuItem(SaveCommand.INSTANCE));
    menu.add(new DynamicMenuItem(SaveAsCommand.INSTANCE));
    menu.add(new ExportMenu());
    menu.addSeparator();
    menu.add(new DynamicMenuItem(PageSetupCommand.INSTANCE));
    menu.add(new DynamicMenuItem(PrintCommand.INSTANCE));
    if (!Platform.isMacintosh()) {
        menu.addSeparator();
        menu.add(new DynamicMenuItem(QuitCommand.INSTANCE));
    }
    DynamicMenuEnabler.add(newMenu);
    DynamicMenuEnabler.add(menu);
    return menu;
}
 
Example 28
Source Project: marathonv5   Source File: RMenuItemTest.java    License: Apache License 2.0 5 votes vote down vote up
private List<JMenuItem> getMenuComponents(JMenu AMenu) {
    Component[] components = AMenu.getMenuComponents();
    List<JMenuItem> items = new ArrayList<JMenuItem>();
    for (int j = 0; j < components.length; j++) {
        if (!(components[j] instanceof AbstractButton)) {
            continue;
        }
        items.add((JMenuItem) components[j]);
    }
    return items;
}
 
Example 29
/**
 * Removes duplicated separators from a JMenu
 *
 * @param menu the menu
 */
private static void removeDuplicatedSeparators(JMenu menu) {
	int separatorCount = 0;
	for (Component component : menu.getMenuComponents()) {
		if (component instanceof JPopupMenu.Separator) {
			separatorCount++;
		} else {
			separatorCount = 0;
		}
		if (separatorCount > 1) {
			menu.remove(component);
		}
	}
}
 
Example 30
Source Project: jdk8u-jdk   Source File: bug8071705.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void runActualTest(GraphicsDevice device,
                                  CountDownLatch latch,
                                  JFrame frame,
                                  boolean [] result)
{
    Rectangle screenBounds = setLocation(frame, device);
    JMenu menu = frame.getJMenuBar().getMenu(0);
    menu.doClick();

    Point location = menu.getLocationOnScreen();
    JPopupMenu pm = menu.getPopupMenu();
    Dimension pmSize = pm.getSize();

    int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
    int height = location.y + yOffset + pmSize.height + menu.getHeight();
    int available = screenBounds.y + screenBounds.height - height;
    if (available > 0) {
        Point origin = pm.getLocationOnScreen();
        if (origin.y < location.y) {
            // growing upward, wrong!
            result[0] = false;
        } else {
            // growing downward, ok!
            result[0] = true;
        }
    } else {
        // there is no space, growing upward would be ok, so we pass
        result[0] = true;
    }
}