Java Code Examples for java.awt.Menu

The following examples show how to use java.awt.Menu. 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
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 2
Source Project: TencentKona-8   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 3
Source Project: spotbugs   Source File: MyMenuBar.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/** Eclipse optimizes away the RCN */
@Override
@DesireWarning("RCN")
public void setHelpMenu(Menu m) {
    synchronized (getTreeLock()) {
        if (helpMenu == m) {
            return;
        }
        if (helpMenu != null) {
            remove(helpMenu);
        }
        if (m.getParent() != this) {
            add(m);
        }
        helpMenu = m;
        if (m != null) {
            super.setHelpMenu(m);
        }
    }
}
 
Example 4
Source Project: jdk8u60   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 5
Source Project: hottub   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 6
Source Project: jdk8u-jdk   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 7
Source Project: jdk8u_jdk   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void test3(final MenuBar menuBar) {
    final Menu helpMenu1 = new Menu("Help Menu1");
    final Menu helpMenu2 = new Menu("Help Menu2");
    menuBar.setHelpMenu(helpMenu1);
    checkCurrentMenu(menuBar, helpMenu1);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, true);
    checkHelpMenu(helpMenu2, false);

    menuBar.setHelpMenu(helpMenu2);
    checkCurrentMenu(menuBar, helpMenu2);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, true);

    menuBar.remove(helpMenu2);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu1, false);
    checkHelpMenu(helpMenu2, false);
}
 
Example 8
Source Project: CQL   Source File: GUI.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
	private static Menu makesToolsMenu() {

		Menu toolsMenu = new Menu("Tools");

		
		MenuItem optionsItem = new MenuItem("Options");
		toolsMenu.add(optionsItem);
		optionsItem.addActionListener(e -> IdeOptions.showOptions());

//		MenuItem chaseItem = new MenuItem("ED Chaser");
//		toolsMenu.add(chaseItem);
//		chaseItem.addActionListener(x -> Chase.dostuff());

		//MenuItem sqlLoaderItem = new MenuItem("SQL Loader");
		//toolsMenu.add(sqlLoaderItem);
		//sqlLoaderItem.addActionListener(x -> SqlLoader.showLoader());

		/* MenuItem sqlMapperItem = new MenuItem("SQL Mapper");
		toolsMenu.add(sqlMapperItem);
		sqlMapperItem.addActionListener(x -> SqlMapper.showGuesser());
*/
		MenuItem sqlCheckItem = new MenuItem("SQL Checker");
		toolsMenu.add(sqlCheckItem);
		sqlCheckItem.addActionListener(x -> new SqlChecker()); 

		MenuItem shredItem = new MenuItem("NR Shredder");
		toolsMenu.add(shredItem);
		shredItem.addActionListener(x -> new NraViewer());

		MenuItem easikItem = new MenuItem("EASIK");
		toolsMenu.add(easikItem);
		easikItem.addActionListener(x -> easik.Easik.main(new String[0]));

		return toolsMenu;
	}
 
Example 9
Source Project: evosql   Source File: DatabaseManager.java    License: Apache License 2.0 5 votes vote down vote up
void addMenuItems(Menu f, String[] m) {

        for (int i = 0; i < m.length; i++) {
            MenuItem item = new MenuItem(m[i].substring(1));
            char     c    = m[i].charAt(0);

            if (c != '-') {
                item.setShortcut(new MenuShortcut(c));
            }

            item.addActionListener(this);
            f.add(item);
        }
    }
 
Example 10
Source Project: jdk8u-jdk   Source File: CMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void setEnabled(final boolean b) {
    super.setEnabled(b);
    final Menu target = (Menu) getTarget();
    final int count = target.getItemCount();
    for (int i = 0; i < count; ++i) {
        MenuItem item = target.getItem(i);
        MenuItemPeer p = (MenuItemPeer) LWCToolkit.targetToPeer(item);
        if (p != null) {
            p.setEnabled(b && item.isEnabled());
        }
    }
}
 
Example 11
private static void test2(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.remove(helpMenu);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 12
private static void test4(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.setHelpMenu(null);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 13
Source Project: jdk8u-jdk   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test4(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.setHelpMenu(null);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 14
Source Project: TrakEM2   Source File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
static private void restoreMenu(final Menu menu) {
	final int n_menuitems = menu.getItemCount();
	for (int i=0; i<n_menuitems; i++) {
		final MenuItem menu_item = menu.getItem(i);
		if (menu_item instanceof Menu) {
			restoreMenu((Menu)menu_item);
		}
		menu_item.setEnabled(true);
	}
}
 
Example 15
Source Project: openjdk-jdk9   Source File: Test4520754.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
 
Example 16
Source Project: TencentKona-8   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test2(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.remove(helpMenu);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 17
Source Project: TencentKona-8   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test4(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.setHelpMenu(null);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 18
Source Project: Scripts   Source File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the index of the MenuItem labeled by the specified string.
 *
 * @param menu
 *            the java.awt.Menu to be parsed
 * @param label
 *            the java.awt.MenuItem label being searched
 * @return the index of the java.awt.MenuItem. Returns {@code -1} if no
 *         match is found, {@code null} if menu is not available.
 */
private Integer getMenuItem(final Menu menu, final String label) {
	int position = -1;
	if (menu == null) {
		return null;
	}
	for (int i = 0; i < menu.getItemCount(); i++) {
		if (menu.getItem(i).getLabel().equals(label)) {
			position = i;
			break;
		}
	}
	return position;
}
 
Example 19
Source Project: jdk8u60   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test4(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.setHelpMenu(null);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 20
Source Project: jdk8u60   Source File: Test4520754.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
 
Example 21
Source Project: jdk8u_jdk   Source File: Test4520754.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
 
Example 22
Source Project: openjdk-jdk9   Source File: ActionEventTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public ActionEventTest() {
    menuBar = new MenuBar();
    Menu menu = new Menu("Menu1");
    MenuItem menuItem = new MenuItem("MenuItem");

    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            System.out.println("actionPerformed");
            int md = ae.getModifiers();
            int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
                    | ActionEvent.SHIFT_MASK;

            isProgInterruption = true;
            mainThread.interrupt();
            if ((md & expectedMask) != expectedMask) {
                throw new RuntimeException("Action Event modifiers are not"
                    + " set correctly.");
            }
        }
    });
    menu.add(menuItem);
    menuBar.add(menu);
    setMenuBar(menuBar);

    instructions = new TextArea(10, 50);
    instructions.setText(
    " This is a manual test\n" +
    " Keep the Alt, Shift & Ctrl Keys pressed while doing next steps\n" +
    " Click 'Menu1' Menu from the Menu Bar\n" +
    " It will show 'MenuItem'\n" +
    " Left mouse Click the 'MenuItem'\n" +
    " Test exits automatically after mouse click.");
    add(instructions);

    setSize(400, 400);
    setVisible(true);
    validate();
}
 
Example 23
Source Project: TrakEM2   Source File: Utils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**Restore ImageJ's MenuBar*/
static public final void restoreMenuBar() {
	final MenuBar menu_bar = Menus.getMenuBar();
	final int n_menus = menu_bar.getMenuCount();
	for (int i=0; i<n_menus;i++) {
		final Menu menu = menu_bar.getMenu(i);
		restoreMenu(menu);
	}
	//make sure there isn't a null menu bar
	//WindowManager.getCurrentWindow().setMenuBar(menu_bar);
}
 
Example 24
Source Project: hottub   Source File: Test4520754.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
 
Example 25
Source Project: openjdk-jdk8u   Source File: RemoveHelpMenu.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void test2(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.remove(helpMenu);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 26
Source Project: jdk8u-jdk   Source File: Test4520754.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // ensure that 4168475 does not regress
    test4168475(Component.class);
    // AWT classes (com.sun.beans.infos.ComponentBeanInfo)
    test(null, Button.class, Component.class, List.class, Menu.class, Panel.class);
    // Swing classes (dt.jar)
    test(null, JApplet.class, JButton.class, JCheckBox.class);
    // user defined classes
    test(Boolean.TRUE, Wombat.class, Foo.class, FooBar.class);
}
 
Example 27
private static void test2(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.remove(helpMenu);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 28
private static void test4(final MenuBar menuBar) {
    final Menu helpMenu = new Menu("Help Menu");
    menuBar.setHelpMenu(helpMenu);
    checkCurrentMenu(menuBar, helpMenu);
    checkMenuCount(menuBar, 1);
    checkHelpMenu(helpMenu, true);

    menuBar.setHelpMenu(null);
    checkCurrentMenu(menuBar, null);
    checkMenuCount(menuBar, 0);
    checkHelpMenu(helpMenu, false);
}
 
Example 29
Source Project: dragonwell8_jdk   Source File: CMenu.java    License: GNU General Public License v2.0 4 votes vote down vote up
public CMenu(Menu target) {
    super(target);
}
 
Example 30
Source Project: hottub   Source File: InputMethodPopupMenu.java    License: GNU General Public License v2.0 4 votes vote down vote up
Object createSubmenu(String label) {
    return new Menu(label);
}