Java Code Examples for javax.swing.JMenu#add()

The following examples show how to use javax.swing.JMenu#add() . 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: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
public JMenu getFileMenu() {
  final JMenu openMenu = new JMenu("Open");
  openMenu.setMnemonic('O');
  openMenu.add(menuItem("New Window", 'N', KeyStroke.getKeyStroke(KeyEvent.VK_N, CMD_CTRL_KEY_MASK),
      this.actionPool.blankWindowAction));
  openMenu.add(menuItem("Cloned Window", 'C', this.actionPool.clonedWindowAction));
  final JMenuItem fileMenuItem = menuItem("File...", 'F', KeyStroke.getKeyStroke(KeyEvent.VK_O, CMD_CTRL_KEY_MASK), this.actionPool.openFileAction);
  // TODO enable the menu item once access control UI is implemented
  fileMenuItem.setEnabled(false);
  openMenu.add(fileMenuItem);

  final JMenu menu = new JMenu("File");
  menu.setMnemonic('F');

  menu.add(openMenu);
  menu.addSeparator();
  menu.add(menuItem("Close", 'C', KeyStroke.getKeyStroke(KeyEvent.VK_W, CMD_CTRL_KEY_MASK), this.actionPool.exitAction));

  return menu;
}
 
Example 2
Source File: GeoServerInput.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Populate workspace list.
 *
 * @param client the client
 * @param parentMenu the parent menu
 */
private void populateWorkspaceList(GeoServerClientInterface client, JMenu parentMenu) {
    for (String workspaceName : client.getWorkspaceList()) {
        JMenuItem workspaceMenuItem = new JMenuItem(workspaceName);
        workspaceMenuItem.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();

                        StyleWrapper styleWrapper = sldData.getStyle();

                        removeStyleFileExtension(styleWrapper);

                        styleWrapper.setWorkspace(workspaceName);
                        client.uploadSLD(styleWrapper, sldData.getSld());
                        client.refreshWorkspace(workspaceName);
                    }
                });
        parentMenu.add(workspaceMenuItem);
    }
}
 
Example 3
Source File: ScreenMenuMemoryLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void showUI() {
    sFrame = new JFrame();
    sFrame.add(new JLabel("Some dummy content"));

    JMenuBar menuBar = new JMenuBar();

    sMenu = new JMenu("Menu");
    JMenuItem item = new JMenuItem("Item");
    sMenu.add(item);

    sMenuItem = new WeakReference<>(item);

    menuBar.add(sMenu);

    sFrame.setJMenuBar(menuBar);

    sFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    sFrame.pack();
    sFrame.setVisible(true);
}
 
Example 4
Source File: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
public void populateBackMore() {
  final List<NavigationEntry> entries = this.window.getBackNavigationEntries();
  final JMenu backMoreMenu = this.backMoreMenu;
  backMoreMenu.removeAll();
  for (final NavigationEntry entry : entries) {
    final String method = entry.getMethod();
    if ("GET".equals(method)) {
      final String title = entry.getTitle();
      final URL url = entry.getUrl();
      final String text = (title == null) || (title.length() == 0) ? url.toExternalForm() : title;
      final Action action = this.actionPool.createGoToAction(entry);
      final JMenuItem menuItem = menuItem(text, action);
      menuItem.setToolTipText(url.toExternalForm());
      backMoreMenu.add(menuItem);
    }
  }
  // backMoreMenu.revalidate();
}
 
Example 5
Source File: SwingSet3.java    From littleluck with Apache License 2.0 6 votes vote down vote up
protected JMenu createLookAndFeelMenu() {
        JMenu menu = new LuckMenu();
        menu.setOpaque(true);
//        menu.setBackground(Color.white);
        menu.setName("lookAndFeel");
        
        // Look for toolkit look and feels first
        UIManager.LookAndFeelInfo lookAndFeelInfos[] = UIManager.getInstalledLookAndFeels();
        lookAndFeel = UIManager.getLookAndFeel().getClass().getName();
        lookAndFeelRadioGroup = new ButtonGroup();
        for(UIManager.LookAndFeelInfo lafInfo: lookAndFeelInfos) {
            menu.add(createLookAndFeelItem(lafInfo.getName(), lafInfo.getClassName()));
        }  
        // Now load any look and feels defined externally as service via java.util.ServiceLoader
        LOOK_AND_FEEL_LOADER.iterator();
        for (LookAndFeel laf : LOOK_AND_FEEL_LOADER) {           
            menu.add(createLookAndFeelItem(laf.getName(), laf.getClass().getName()));
        }
         
        return menu;
    }
 
Example 6
Source File: MainMenuBar.java    From Carcassonne with Eclipse Public License 2.0 5 votes vote down vote up
private void buildColorMenu() {
    itemSettings = new JMenuItem[GameSettings.MAXIMAL_PLAYERS];
    menuColor = new JMenu(COLOR_SETTINGS);
    for (int i = 0; i < itemSettings.length; i++) {
        itemSettings[i] = new JMenuItem();
        itemSettings[i].addActionListener(scoreboard.getSettingsListener(i));
        menuColor.add(itemSettings[i]);
    }
}
 
Example 7
Source File: FormUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Make a JMenu from an Action List 
 * @param actions the Action List
 * @return JMenu 
 */
public static JMenu toMenu(List<Action> actions) {
	JMenu menu = new JMenu();
	
	for (Action a : actions)
		menu.add(a);
	
	return menu;
}
 
Example 8
Source File: bug8071705.java    From openjdk-jdk8u-backup with 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 9
Source File: CodeceptionActionsFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public JMenuItem getPopupPresenter() {
    if (phpModule == null) {
        return new Actions.MenuItem(this, false);
    }
    JMenu menu = new JMenu(Bundle.CodeceptionActionsFactory_name());
    menu.add(new BootstrapAction(phpModule));
    menu.add(new BuildAction(phpModule));
    menu.add(new CleanAction(phpModule));
    return menu;
}
 
Example 10
Source File: AppMenuBar.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private JMenu createFileMenu() {
    JMenu file = new JMenu("File");
    file.setMnemonic('F');

    file.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("New Project", sActionListener))), 'N'));
    file.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Open Project", sActionListener))), 'O'));
    file.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Save Project", sActionListener))), 'S'));
    file.addSeparator();

    file.add(sActionListener.getMainFrame().getRecentItems());
    file.add(sActionListener.getMainFrame().getTestDesign().getTestCaseComp().getTestCaseHistory());

    file.add(Utils.createMenuItem("Restart", sActionListener));

    file.add(withShortCut(
            Utils.createMenuItem("Quit", sActionListener)));

    return file;
}
 
Example 11
Source File: ShelveMenu.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JMenu createMenu () {
    JMenu menu = new JMenu(this);
    for (JComponent item : ShelveUtils.getShelveMenuItems(ctx, lkp)) {
        if (item == null) {
            menu.addSeparator();
        } else {
            menu.add(item);
        }
    }
    return menu;
}
 
Example 12
Source File: MainMenuBar.java    From Carcassonne with 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 13
Source File: AppMenuBar.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private JMenu createObjectMenu() {
    JMenu object = new JMenu("Automation");
    object.setMnemonic('A');

    object.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Object Spy", sActionListener))), 'S'));
    object.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Object Heal", sActionListener))), 'H'));
    object.addSeparator();
    object.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Image Spy", sActionListener))), 'I'));
    object.add(withMnemonics(
            withShortCut(
                    withIcon(
                            Utils.createMenuItem("Mobile Spy", sActionListener))), 'M'));
    object.addSeparator();
    object.add(
            withMnemonics(
                    withIcon(
                            Utils.createMenuItem("Inject Script", sActionListener)), 'n'));
    object.add(
            withMnemonics(Utils.createMenuItem("Create CM Project", sActionListener), 'C'));
    return object;
}
 
Example 14
Source File: SessionMenu.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected JMenu createComponent() {
   JMenu menu = new JMenu(label);
   menu.add(new JMenuItem(controller.getChangePasswordAction()));
   menu.add(new JMenuItem(controller.getReconnectAction()));
   menu.addSeparator();
   menu.add(new JMenuItem(controller.getLaunchBrowser()));
   menu.addSeparator();
   menu.add(new JMenuItem(controller.getLogoutAndLoginAction()));
   menu.add(new JMenuItem(controller.getLogoutAndQuitAction()));
   menu.add(new JMenuItem(controller.getQuitAction()));
   return menu;
}
 
Example 15
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void loadStopQueueMenu(JMenu menu) {
	menu.removeAll();
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		if (q.isRunning()) {
			JMenuItem mitem = new JMenuItem(q.getName());
			mitem.setForeground(ColorResource.getLightFontColor());
			mitem.setName("STOP:" + q.getQueueId());
			mitem.addActionListener(this);
			menu.add(mitem);
		}
	}
}
 
Example 16
Source File: SwingSet2.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
	 * Creates a generic menu item.
	 *
	 * @param menu the menu
	 * @param label the label
	 * @param mnemonic the mnemonic
	 * @param accessibleDescription the accessible description
	 * @param action the action
	 * @return the j menu item
	 */
	public JMenuItem createMenuItem(JMenu menu, String label, String mnemonic,
			String accessibleDescription, Action action) {
		JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(getString(label)));
		
//		mi.setBorder(BorderFactory.createEmptyBorder());
		mi.setMnemonic(getMnemonic(mnemonic));
		mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
		mi.addActionListener(action);
		if(action == null) {
			mi.setEnabled(false);
		}
		return mi;
	}
 
Example 17
Source File: NewFilterPopup.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public JMenuItem getPopupPresenter() {
    JMenu result = new JMenu("Add Filter..");
    for (NewFilterAction di : Lookup.getDefault().lookupAll(NewFilterAction.class)) {
        result.add(new JMenuItem(di.getAction(filterNode)));
    }
    return result;
}
 
Example 18
Source File: SimMenuBar.java    From the-one with GNU General Public License v3.0 4 votes vote down vote up
private void init() {
	JMenu pfMenu = new JMenu("Playfield options");
	JMenu pfToolsMenu = new JMenu("Tools");
	JMenu help = new JMenu("Help");
	JMenu nodeFilters = new JMenu("Add node filter");
	Settings settings = new Settings(UNDERLAY_NS);

	if (settings.contains("fileName")) {
		// create underlay image menu item only if filename is specified
		enableBgImage = createCheckItem(pfMenu,"Show underlay image",
				false, null);
	}

	settings.setNameSpace(gui.MainWindow.GUI_NS);

	showNodeName = createCheckItem(pfMenu, "Show node name strings",
			true, SHOW_NODE_NAMESTR_S);
	showNodeCoverage = createCheckItem(pfMenu,
			"Show node radio coverages", true, SHOW_RADIO_COVERAGES_S);
	showNodeConnections = createCheckItem(pfMenu,
			"Show node connections", true, SHOW_CONNECTIONS_S);
	showBuffer = createCheckItem(pfMenu,
			"Show message buffer", true, SHOW_BUFFER_S);
	focusOnClick = createCheckItem(pfMenu,
			"Focus to closest node on mouse click", false,FOCUS_ON_CLICK_S);

	enableMapGraphic = createCheckItem(pfMenu,"Show map graphic",
			true, null);
	autoClearOverlay = createCheckItem(pfMenu, "Autoclear overlay",
			true, null);
	clearOverlay = createMenuItem(pfToolsMenu, "Clear overlays");


	pfToolsMenu.addSeparator();
	addNodeMessageFilter = createMenuItem(nodeFilters, "message filter");
	pfToolsMenu.add(nodeFilters);
	clearNodeFilters = createMenuItem(pfToolsMenu, "Clear node filters");

	updatePlayfieldSettings();

	about = createMenuItem(help,"about");
	this.add(pfMenu);
	this.add(pfToolsMenu);
	this.add(Box.createHorizontalGlue());
	this.add(help);
}
 
Example 19
Source File: FigureWidget.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void addFigureToMenu(JMenu m, final Figure f, boolean successor, int depth) {

        Action a = diagramScene.createGotoAction(f);


        m.add(a);

        if (depth > 0) {
            String name = "Predecessors";
            if (successor) {
                name = "Successors";
            }

            JMenu subMenu = new JMenu(name);
            addFigureToSubMenu(subMenu, f, successor, depth);
            m.add(subMenu);
        }

    }
 
Example 20
Source File: MapEditor.java    From javagame with MIT License 4 votes vote down vote up
/**
 * ���j���[�o�[���쐬
 *
 */
private void createMenu() {
    JMenu fileMenu = new JMenu("�t�@�C��");
    JMenu editMenu = new JMenu("�ҏW");
    JMenu eventMenu = new JMenu("�C�x���g");
    JMenu helpMenu = new JMenu("�w���v");
    
    newItem = new JMenuItem("�V�K�쐬");
    openItem = new JMenuItem("�J��");
    saveItem = new JMenuItem("�ۑ�");
    exitItem = new JMenuItem("�I��");
    fillItem = new JMenuItem("�h��‚Ԃ�");
    addEventItem = new JMenuItem("�lj�");
    removeEventItem = new JMenuItem("�폜");
    versionItem = new JMenuItem("�o�[�W�������");
    
    fileMenu.add(newItem);
    fileMenu.add(openItem);
    fileMenu.add(saveItem);
    fileMenu.addSeparator();  // ��؂�
    fileMenu.add(exitItem);
    editMenu.add(fillItem);
    eventMenu.add(addEventItem);
    eventMenu.add(removeEventItem);
    helpMenu.add(versionItem);
    
    newItem.addActionListener(this);
    openItem.addActionListener(this);
    saveItem.addActionListener(this);
    exitItem.addActionListener(this);
    fillItem.addActionListener(this);
    addEventItem.addActionListener(this);
    removeEventItem.addActionListener(this);
    versionItem.addActionListener(this);
    
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(eventMenu);
    menuBar.add(helpMenu);
    
    setJMenuBar(menuBar);
}