Java 8 JMenu - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JMenu class.

This code example shows how to use the following methods:add, addSeparator
public class TestMMenu { 
    private MMenu mmenu;
 
    @Before 
    public void setUp() throws Exception {
        JMenu menu = new JMenu("File");
        menu.add("New");
        menu.add(new JButton("Open"));
        menu.addSeparator();
        JMenu child = new JMenu("Recent Files");
        child.add("MMenu.java");
        JMenu grandChild = new JMenu("Edit Box");
        grandChild.add("Edit...");
        child.add(grandChild);
        menu.add(child);
        mmenu = new MMenu(menu, "menu.name", null, WindowMonitor.getInstance());
    } 
 
    @After 
    public void tearDown() throws Exception {
    } 
6
CodeRank
This code example shows how to use the following methods:setMnemonic, add
        fileMenu.add(closeItem);
 
        label = resources.getString("system-frame.menu.edit");
        mnemonic = (Character) resources.getObject(
                "system-frame.menu.edit.mnemonic"); 
        final JMenu editMenu = new JMenu(label);
        editMenu.setMnemonic(mnemonic.charValue());
 
        label = resources.getString("system-frame.menu.edit.copy");
        mnemonic = (Character) resources.getObject(
                "system-frame.menu.edit.copy.mnemonic"); 
        final JMenuItem copyItem = new JMenuItem(label, mnemonic.charValue());
        copyItem.setActionCommand(COPY_COMMAND);
        copyItem.addActionListener(this);
        editMenu.add(copyItem);
 
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        return menuBar;
 
6
CodeRank
This code example shows how to use the following methods:getItemCount, getMenuComponent
     * Make menu scrollable 
     * @param menu {@link JMenu} 
     */ 
    public static void makeScrollableMenu(JMenu menu) { 
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        if(menu.getItemCount()>0) {
            // We use 80% of height 
            int maxItems = (int)Math.round(
                    screenSize.getHeight()*0.8/menu.getMenuComponent(0).getPreferredSize().getHeight());
            MenuScroller.setScrollerFor(menu, maxItems, 200);
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setMnemonic, add, addSeparator
6
CodeRank
This code example shows how to use the following methods:add, addSeparator
    parent = owner;
 
    onFile = new JMenu("File");
    onEdit = new JMenu("Edit");
    onView = new JMenu("View");
    onOptions = new JMenu("Options");
    onHelp = new JMenu("Help");
 
    onLookFeel = new MenuLooknFeel("Look And Feel", parent);
 
    initMenuItems(); 
 
    onFile.add(onFileOpen);
    onFile.add(onFileSave);
    onFile.add(onFileExit);
 
    onEdit.add(onEditCut);
    onEdit.add(onEditCopy);
 
    onView.add(onViewCPool);

6
CodeRank
This code example shows how to use the following methods:setName, getText, setText
     * @param commandGroup the command group, must not be <code>null</code> 
     * 
     * @return the menu item 
     */ 
    public JMenuItem createMenuItem(CommandGroup commandGroup) {
        JMenu menu = new JMenu(commandGroup.getAction());
        menu.setName(commandGroup.getCommandID());
        // Ensure that the menu has some text, so that is guranteed to be visible for the user 
        if (menu.getText() == null) {
            menu.setText(commandGroup.getCommandID());
        } 
        enableHelp(menu, commandGroup);
        return menu;
    } 
 
    /** 
     * Creates a tool bar button for the given executable command. 
     * 
     * @param command the executable command, must not be <code>null</code> 
     * 
6
CodeRank
This code example shows how to use the following methods:setMnemonic, add, addSeparator
  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;
  } 
 
6
CodeRank
This code example shows how to use the following methods:add
		// this item does nothing, it displays a popup 
	} 
 
	public JMenuItem getPopupPresenter()
	{ 
		JMenu menu = new JMenu();		
		Mnemonics.setLocalizedText(menu, getName());		
		 
		JMenuItem item = new JMenuItem();
		Mnemonics.setLocalizedText(item, item.getText());
		Actions.connect(item, (Action)SystemAction.get(BuildSoupAction.class), true);
		menu.add(item);
		 
		item = new JMenuItem();
		Mnemonics.setLocalizedText(item, item.getText());
		Actions.connect(item, (Action)SystemAction.get(BuidOEMMAction.class), true);
		menu.add(item);
		 
		item = new JMenuItem();
		Mnemonics.setLocalizedText(item, item.getText());

5
CodeRank
This code example shows how to use the following methods:setMnemonic, add, addSeparator
		return menuBar;
	} 
	 
	private JMenu createFileMenu(int shortcutKeyMask) {
		// create file-menu: 
		JMenu menu = new JMenu( "File" );
		menu.setMnemonic('f');
  
		JMenuItem item = new JMenuItem( "Save", 'S' );
		item.setAccelerator( KeyStroke.getKeyStroke( 'S', shortcutKeyMask ));
		item.addActionListener( this );
		menu.add( item );
		this.menuSave = item;
 
		item = new JMenuItem( "Save As...", 'A' );
		item.addActionListener( this );
		menu.add( item );
		this.menuSaveAs = item;
 
		item = new JMenuItem( "Save PNG Image As...", 'P' );

6
CodeRank
This code example shows how to use the following methods:setMnemonic, setText
   * @param keyPrefix the common prefix for that menu 
   * @return the created menu 
   */ 
  public JMenu createMenu(final String keyPrefix)
  { 
    final JMenu retval = new JMenu();
    retval.setText(getString(keyPrefix + ".name"));
    retval.setMnemonic(getMnemonic(keyPrefix + ".mnemonic").intValue());
    return retval;
  } 
 
  /** 
   * Returns a URL pointing to a resource located in the classpath. The 
   * resource is looked up using the given key. 
   * <p/> 
   * Example: The load a file named 'logo.gif' which is stored in a java 
   * package named 'org.jfree.resources': 
   * <pre> 
   * mainmenu.logo=org/jfree/resources/logo.gif 
   * </pre> 
6
CodeRank
See Code Examples for Java 8 JMenu Methods: