List of usage examples for javax.swing JMenu addSeparator
public void addSeparator()
From source file:components.MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;// w w w . jav a 2 s. co m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:MenuLookDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from w w w . jav a 2 s . c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); // a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menu.add(menuItem); // a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); menu.add(rbMenuItem); // a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); menu.add(cbMenuItem); // a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); submenu.add(menuItem); menu.add(submenu); // Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:org.jdal.swing.PageableTable.java
/** * Create the right menu bar/*w w w . ja va 2s .c om*/ */ private void createMenu() { rightMenuBar = new JMenuBar(); rightMenuBar.setLayout(new BoxLayout(rightMenuBar, BoxLayout.PAGE_AXIS)); rightMenuBar.setMargin(new Insets(0, 0, 0, 0)); // Add Visibility menu JMenu menu = new JMenu(); menu.setMargin(new Insets(0, 0, 0, 0)); menu.setIcon(visibilityMenuIcon); menu.setMaximumSize(new Dimension(50, 50)); visibilityBox = new VisibilityBox(columnDescriptors); menu.add(visibilityBox); menu.getPopupMenu().addPopupMenuListener(new VisibilityPopupListener()); JMenuItem okMenuItem = new JMenuItem(new OkVisibilityAction()); JMenuItem cancelMenuItem = new JMenuItem(new CancelVisibilityAction()); menu.addSeparator(); menu.add(okMenuItem); menu.add(cancelMenuItem); rightMenuBar.add(menu); JMenu prefsMenu = new JMenu(); prefsMenu.setMargin(new Insets(0, 0, 0, 0)); prefsMenu.setIcon(userMenuIcon); prefsMenu.setMaximumSize(new Dimension(50, 50)); prefsMenu.add(new JMenuItem(new LoadPreferencesAction(this, messageSource .getMessage("PageableTable.loadPreferences", null, "Load Preferences", Locale.getDefault())))); prefsMenu.add(new JMenuItem(new SavePreferencesAction(this, messageSource .getMessage("PageableTable.savePreferences", null, "Save Preferences", Locale.getDefault())))); rightMenuBar.add(prefsMenu); rightMenuBar.add(Box.createVerticalGlue()); // Add menu bar to right add(rightMenuBar, BorderLayout.EAST); }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initFileMenu(JMenu mnFile) { mnFile.removeAll();//from w w w . j a v a 2 s . c om // non-dynamic for (MyAction action : fileActions) { if (action == null) { mnFile.addSeparator(); } else { JMenuItem item = mnFile.add(action); if (action.accelerator != null) { item.setAccelerator(action.accelerator); } } } // import (not in action list as doesn't appear on toolbar) mnFile.addSeparator(); JMenu mnImport = new JMenu("Import"); mnFile.add(mnImport); class ImportPair { String menuString; SupportedFileType type; public ImportPair(String menuString, SupportedFileType type) { super(); this.menuString = menuString; this.type = type; } } for (final ImportPair type : new ImportPair[] { new ImportPair("Comma separated (CSV) text", SupportedFileType.CSV), new ImportPair("Tab separated text", SupportedFileType.TABBED), new ImportPair("Excel", SupportedFileType.EXCEL), new ImportPair("Shapefile (link geometry to original file)", SupportedFileType.SHAPEFILE_LINKED_GEOM), new ImportPair("Shapefile (copy geometry into spreadsheet)", SupportedFileType.SHAPEFILE_COPIED_GEOM), }) { mnImport.add(new AbstractAction(type.menuString) { @Override public void actionPerformed(ActionEvent e) { importFile(type.type); } }); } // dynamic mnFile.addSeparator(); List<File> recent = PreferencesManager.getSingleton().getRecentFiles(); for (int i = 0; i < recent.size(); i++) { final File file = recent.get(i); String s = Integer.toString(i + 1) + ". " + file.getAbsolutePath(); int maxLen = 100; if (s.length() > maxLen) { s = s.substring(0, maxLen) + "..."; } mnFile.add(new MyAction(s, "Load file " + file.getAbsolutePath(), null, null, false, null) { @Override public void actionPerformed(ActionEvent e) { if (!canCloseDatastore()) { return; } openFile(file); updateAppearance(); } }); } // clear recent mnFile.addSeparator(); mnFile.add(new MyAction("Clear recent files", "Clear recent files", null, null, false, null) { @Override public void actionPerformed(ActionEvent e) { PreferencesManager.getSingleton().clearRecentFiles(); } }); // finally exit mnFile.addSeparator(); JMenuItem item = mnFile.add(new MyAction("Exit", "Exit", null, null, false, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.Event.CTRL_MASK)) { @Override public void actionPerformed(ActionEvent e) { dispose(); System.exit(0); } }); item.setAccelerator(((MyAction) item.getAction()).accelerator); mnFile.validate(); }
From source file:ucar.unidata.idv.control.chart.ChartManager.java
/** * add menu items/*w w w . j av a 2 s . c o m*/ * * @param items items */ public void addViewMenuItems(List items) { JMenu layoutMenu = new JMenu("Layout"); items.add(layoutMenu); JMenuItem mi; int[] types = { LAYOUT_GRAPH, LAYOUT_VSTACK, LAYOUT_HSTACK, LAYOUT_2COLGRID, LAYOUT_3COLGRID, LAYOUT_TAB }; String[] names = { "Grid", "Vertical", "Horizontal", "2 Columns", "3 Columns", "Tabs" }; layoutMenu.add(mi = GuiUtils.makeMenuItem("Change Grid Layout", this, "editLayout")); layoutMenu.addSeparator(); mi.setEnabled(layout == LAYOUT_GRAPH); for (int i = 0; i < types.length; i++) { layoutMenu.add(mi = GuiUtils.makeMenuItem(names[i], this, "setLayoutType", new Integer(types[i]))); if (types[i] == layout) { mi.setEnabled(false); } } items.add(GuiUtils.MENU_SEPARATOR); for (ChartHolder chartHolder : chartHolders) { if (!chartHolder.getBeingShown()) { continue; } List chartItems = new ArrayList(); chartHolder.getMenuItems(chartItems); items.add(GuiUtils.makeMenu("Chart: " + chartHolder.getName(), chartItems)); } }
From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java
protected JPopupMenu createPopupMenu() { if (TABLE.getSelectionModel().isSelectionEmpty()) return null; JPopupMenu menu = new JPopupMenu(); menu.add(new JMenuItem(LAUNCH_ACTION)); menu.add(new JMenuItem(ENQUEUE_ACTION)); menu.addSeparator();// w w w . j av a 2 s. c o m menu.add(new JMenuItem(RESUME_ACTION)); menu.addSeparator(); menu.add(new JMenuItem(DELETE_ACTION)); menu.add(new JMenuItem(RENAME_ACTION)); menu.addSeparator(); DataLine[] dls = TABLE.getSelectedDataLines(); boolean dirSelected = false; boolean fileSelected = false; for (int i = 0; i < dls.length; i++) { if (((LibraryTableDataLine) dls[i]).getFile().isDirectory()) dirSelected = true; else fileSelected = true; if (dirSelected && fileSelected) break; } if (dirSelected) { if (GUIMediator.isPlaylistVisible()) ENQUEUE_ACTION.setEnabled(false); DELETE_ACTION.setEnabled(false); RENAME_ACTION.setEnabled(false); if (fileSelected) { JMenu sharingMenu = new JMenu(GUIMediator.getStringResource("LIBRARY_TABLE_SHARING_SUB_MENU")); sharingMenu.add(new JMenuItem(SHARE_ACTION)); sharingMenu.add(new JMenuItem(UNSHARE_ACTION)); sharingMenu.add(new JMenuItem(ANNOTATE_ACTION)); sharingMenu.add(new JMenuItem(PUBLISH_ACTION)); sharingMenu.addSeparator(); sharingMenu.add(new JMenuItem(SHARE_FOLDER_ACTION)); sharingMenu.add(new JMenuItem(UNSHARE_FOLDER_ACTION)); menu.add(sharingMenu); } else { menu.add(new JMenuItem(SHARE_FOLDER_ACTION)); menu.add(new JMenuItem(UNSHARE_FOLDER_ACTION)); } } else { if (GUIMediator.isPlaylistVisible()) ENQUEUE_ACTION.setEnabled(true); DELETE_ACTION.setEnabled(true); RENAME_ACTION.setEnabled(!_isIncomplete); menu.add(new JMenuItem(SHARE_ACTION)); menu.add(new JMenuItem(UNSHARE_ACTION)); menu.add(new JMenuItem(ANNOTATE_ACTION)); menu.add(new JMenuItem(PUBLISH_ACTION)); } menu.addSeparator(); menu.add(createSearchSubMenu((LibraryTableDataLine) dls[0])); menu.add(createAdvancedMenu((LibraryTableDataLine) dls[0])); LICENSE_ACTION.setEnabled(dls != null && dls[0] != null && ((LibraryTableDataLine) dls[0]).isLicensed()); return menu; }
From source file:components.MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from www. j a v a2 s . c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Build menu.//from w ww. j a v a 2 s. co m */ public void makeMenu() { JMenuItem menuItem; JMenu menu; JMenu submenu; menuBar = new JMenuBar(); setJMenuBar(menuBar); menu = new JMenu(Menu.MENU_FILE); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.EXPORT_MENU); menu.add(submenu); //submenu.setMnemonic( KeyEvent.VK_E ); SchemeExporter.makeSchemeExportMenu(submenu, getActionListener()); // Export window graphics submenu.add(GraphicsExporter.getExportMenu()); menu.addSeparator(); menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu = new JMenu(Menu.MENU_EDIT); menu.setMnemonic(KeyEvent.VK_E); menu.add(undoAction); menu.add(redoAction); menu.add(cloneAction); menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true); painterEnabled.addActionListener(getActionListener()); menu.add(painterEnabled); menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas = Editor.getInstance().getCurrentCanvas(); if (canvas == null || !canvas.getPackage().hasPainters()) { painterEnabled.setVisible(false); } else { painterEnabled.setVisible(true); painterEnabled.setSelected(canvas.isEnableClassPainter()); } } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_VIEW); menu.setMnemonic(KeyEvent.VK_V); gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid()); gridCheckBox.setMnemonic('G'); gridCheckBox.addActionListener(getActionListener()); menu.add(gridCheckBox); ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls()); ctrlCheckBox.setMnemonic('C'); ctrlCheckBox.addActionListener(getActionListener()); menu.add(ctrlCheckBox); showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true); showPortCheckBox.addActionListener(getActionListener()); menu.add(showPortCheckBox); showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false); showObjectNamesCheckBox.addActionListener(getActionListener()); menu.add(showObjectNamesCheckBox); //sync View with current canvas menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas; if ((canvas = getCurrentCanvas()) == null) return; gridCheckBox.setSelected(canvas.isGridVisible()); ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible()); showPortCheckBox.setSelected(canvas.isDrawPorts()); showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_PACKAGE); menu.setMnemonic(KeyEvent.VK_P); menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (Desktop.isDesktopSupported()) { menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLOSE_ALL); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu.add(new JSeparator()); final JMenu submenuRecent = new JMenu(Menu.RECENT); submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { final JMenuItem empty = new JMenuItem("Empty"); @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeRecentSubMenu(submenuRecent); if (submenuRecent.getMenuComponentCount() == 0) { submenuRecent.add(empty); empty.setEnabled(false); } else { if (!((submenuRecent.getMenuComponentCount() == 1) && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) { submenuRecent.remove(empty); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menu.add(submenuRecent); final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME); menuScheme.setMnemonic(KeyEvent.VK_S); makeSchemeMenu(menuScheme); menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeSchemeMenu(menuScheme); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); /* * menuItem = new JMenuItem("Planner"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); * menuItem = new JMenuItem("Plan, compile, run"); * menuItem.setActionCommand("Run"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); */ // menuScheme.setMnemonic(KeyEvent.VK_A); menuBar.add(menuScheme); menu = new JMenu(Menu.MENU_OPTIONS); menu.setMnemonic(KeyEvent.VK_O); menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.FONTS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SETTINGS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.MENU_LAF); submenu.setMnemonic(KeyEvent.VK_L); Look.getInstance().createMenuItems(submenu); menu.add(submenu); menuBar.add(menu); makeToolsMenu(menuBar); menu = new JMenu(Menu.MENU_HELP); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from w ww . j a v a 2s. co m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:gui.DownloadManagerGUI.java
private JMenuBar initMenuBar() { JMenuBar menuBar = new JMenuBar(); ///////////////////////////////////////////////////////////////////////// JMenu fileMenu = new JMenu(messagesBundle.getString("downloadManagerGUI.fileMenu.name")); exportDataItem = new JMenuItem("Export Data..."); importDataItem = new JMenuItem("Import Data..."); exitItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.exitItem.name")); exitItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.exitItem.iconPath")))); // NOI18N exportDataItem.setEnabled(false);// www . j ava 2s .c o m importDataItem.setEnabled(false); // fileMenu.add(exportDataItem); // fileMenu.add(importDataItem); fileMenu.addSeparator(); fileMenu.add(exitItem); ///////////////////////////////////////////////////////////////////////// JMenu windowMenu = new JMenu(messagesBundle.getString("downloadManagerGUI.windowMenu.name")); JMenu showMenu = new JMenu(messagesBundle.getString("downloadManagerGUI.showMenu.name")); prefsItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.prefsItem.name")); prefsItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.prefsItem.iconPath")))); JCheckBoxMenuItem showFormItem = new JCheckBoxMenuItem( messagesBundle.getString("downloadManagerGUI.showFormItem.name")); showFormItem.setSelected(true); showMenu.add(showFormItem); windowMenu.add(showMenu); windowMenu.add(prefsItem); exportDataItem.addActionListener(this); importDataItem.addActionListener(this); exitItem.addActionListener(this); prefsItem.addActionListener(this); ///////////////////////////////////////////////////////////////////////// JMenu downloadsMenu = new JMenu(messagesBundle.getString("downloadManagerGUI.downloadsMenu.name")); newDownloadItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.newDownloadItem.name")); newDownloadItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.newDownloadItem.iconPath")))); openItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.openItem.name")); openFolderItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.openFolderItem.name")); resumeItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.resumeItem.name")); resumeItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.resumeItem.iconPath")))); pauseItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.pauseItem.name")); pauseItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.pauseItem.iconPath")))); pauseAllItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.pauseAllItem.name")); pauseAllItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.pauseAllItem.iconPath")))); clearItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.clearItem.name")); clearItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.clearItem.iconPath")))); clearAllCompletedItem = new JMenuItem( messagesBundle.getString("downloadManagerGUI.clearAllCompletedItem.name")); clearAllCompletedItem.setIcon(new javax.swing.ImageIcon(getClass() .getResource(messagesBundle.getString("downloadManagerGUI.clearAllCompletedItem.iconPath")))); reJoinItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.reJoinItem.name")); reJoinItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.reJoinItem.iconPath")))); reDownloadItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.reDownloadItem.name")); reDownloadItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.reDownloadItem.iconPath")))); moveToQueueItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.moveToQueueItem.name")); removeFromQueueItem = new JMenuItem( messagesBundle.getString("downloadManagerGUI.removeFromQueueItem.name")); propertiesItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.propertiesItem.name")); propertiesItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.propertiesItem.iconPath")))); downloadsMenu.add(newDownloadItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(openItem); downloadsMenu.add(openFolderItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(resumeItem); downloadsMenu.add(pauseItem); downloadsMenu.add(pauseAllItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(clearItem); downloadsMenu.add(clearAllCompletedItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(reJoinItem); downloadsMenu.add(reDownloadItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(moveToQueueItem); downloadsMenu.add(removeFromQueueItem); downloadsMenu.add(new JSeparator()); downloadsMenu.add(propertiesItem); newDownloadItem.addActionListener(this); openItem.addActionListener(this); openFolderItem.addActionListener(this); resumeItem.addActionListener(this); pauseItem.addActionListener(this); pauseAllItem.addActionListener(this); clearItem.addActionListener(this); clearAllCompletedItem.addActionListener(this); reDownloadItem.addActionListener(this); moveToQueueItem.addActionListener(this); removeFromQueueItem.addActionListener(this); propertiesItem.addActionListener(this); setStateOfMenuItems(); ///////////////////////////////////////////////////////////////////////// JMenu helpMenu = new JMenu(messagesBundle.getString("downloadManagerGUI.helpMenu.name")); aboutItem = new JMenuItem(messagesBundle.getString("downloadManagerGUI.aboutItem.name")); aboutItem.setIcon(new javax.swing.ImageIcon( getClass().getResource(messagesBundle.getString("downloadManagerGUI.aboutItem.iconPath")))); helpMenu.add(aboutItem); aboutItem.addActionListener(this); menuBar.add(fileMenu); menuBar.add(windowMenu); menuBar.add(downloadsMenu); menuBar.add(helpMenu); showFormItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) ev.getSource(); if (menuItem.isSelected()) { mainSplitPane.setDividerLocation((int) categoryPanel.getMinimumSize().getWidth()); } categoryPanel.setVisible(menuItem.isSelected()); } }); fileMenu.setMnemonic(KeyEvent.VK_F); exitItem.setMnemonic(KeyEvent.VK_X); prefsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); importDataItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.CTRL_MASK)); return menuBar; }