List of usage examples for javax.swing JMenu setMnemonic
@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic") public void setMnemonic(int mnemonic)
From source file:com.net2plan.gui.GUINet2Plan.java
private void start() { setExtendedState(JFrame.MAXIMIZED_BOTH); setMinimumSize(new Dimension(800, 600)); itemObject = new DualHashBidiMap<JMenuItem, Object>(); URL iconURL = GUINet2Plan.class.getResource("/resources/gui/icon.png"); ImageIcon icon = new ImageIcon(iconURL); setIconImage(icon.getImage());// w ww .java 2 s .co m setTitle("Net2Plan"); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(CLOSE_NET2PLAN); getContentPane().setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow]")); container = new JPanel(new MigLayout("", "[]", "[]")); container.setBorder(new LineBorder(Color.BLACK)); container.setLayout(new MigLayout("fill")); getContentPane().add(container, "grow"); /* Create menu bar */ menu = new JMenuBar(); setJMenuBar(menu); /* File menu */ JMenu file = new JMenu("File"); file.setMnemonic('F'); menu.add(file); optionsItem = new JMenuItem("Options"); optionsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_DOWN_MASK)); optionsItem.addActionListener(this); file.add(optionsItem); classPathEditorItem = new JMenuItem("Classpath editor"); classPathEditorItem.addActionListener(this); file.add(classPathEditorItem); errorConsoleItem = new JMenuItem("Show Java console"); errorConsoleItem.addActionListener(this); errorConsoleItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, InputEvent.ALT_DOWN_MASK)); file.add(errorConsoleItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_DOWN_MASK)); file.add(exitItem); /* Help menu */ JMenu help = new JMenu("Help"); help.setMnemonic('H'); menu.add(help); aboutItem = new JMenuItem("About"); aboutItem.addActionListener(this); help.add(aboutItem); itemObject.put(aboutItem, showAbout()); helpItem = new JMenuItem("User's guide"); helpItem.addActionListener(this); helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.VK_UNDEFINED)); help.add(helpItem); javadocItem = new JMenuItem("Library API Javadoc"); javadocItem.addActionListener(this); help.add(javadocItem); javadocExamplesItem = new JMenuItem("Built-in Examples Javadoc"); javadocExamplesItem.addActionListener(this); help.add(javadocExamplesItem); keyCombinationItem = new JMenuItem("Show tool key combinations"); keyCombinationItem.addActionListener(this); keyCombinationItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, KeyEvent.ALT_DOWN_MASK)); help.add(keyCombinationItem); usedKeyStrokes = new LinkedHashSet<KeyStroke>(); refreshMenu(); container.add(showAbout(), "align center"); container.revalidate(); new JFileChooser(); /* Do not remove! It is used to avoid slow JFileChooser first-time loading once Net2Plan is shown to the user */ setVisible(true); }
From source file:adams.gui.tools.FileMonitorPanel.java
/** * Creates a menu bar (singleton per panel object). Can be used in frames. * * @return the menu bar//w ww . j av a 2 s . co m */ @Override public JMenuBar getMenuBar() { JMenuBar result; JMenu menu; JMenu submenu; JMenuItem menuitem; if (m_MenuBar == null) { result = new JMenuBar(); // File menu = new JMenu("File"); result.add(menu); menu.setMnemonic('F'); menu.addChangeListener((ChangeEvent e) -> updateMenu()); menuitem = new JMenuItem("Open...", GUIHelper.getIcon("open.gif")); menuitem.setMnemonic('O'); menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed O")); menuitem.addActionListener((ActionEvent e) -> open()); menu.add(menuitem); m_MenuItemOpen = menuitem; // File/Recent files submenu = new JMenu("Open recent"); menu.add(submenu); m_RecentFilesHandler = new RecentFilesHandler<>(SESSION_FILE, 5, submenu); m_RecentFilesHandler.addRecentItemListener(new RecentItemListener<JMenu, File>() { public void recentItemAdded(RecentItemEvent<JMenu, File> e) { // ignored } public void recentItemSelected(RecentItemEvent<JMenu, File> e) { open(e.getItem()); } }); m_MenuItemOpenRecent = submenu; menu.addSeparator(); menuitem = new JMenuItem("Close", GUIHelper.getIcon("exit.png")); menuitem.setMnemonic('C'); menuitem.setAccelerator(GUIHelper.getKeyStroke("ctrl pressed Q")); menuitem.addActionListener((ActionEvent e) -> close()); menu.add(menuitem); m_MenuItemClose = menuitem; // update menu m_MenuBar = result; updateMenu(); } else { result = m_MenuBar; } return result; }
From source file:net.chaosserver.timelord.swingui.TimelordMenu.java
/** * Creates the file menu.//from w ww.j a v a2s .co m * * @return the new file menu */ protected JMenu createFileMenu() { JMenu fileMenu = new JMenu(resourceBundle.getString(RROOT + ".fileMenuName")); JMenuItem menuItem; fileMenu.setMnemonic(KeyEvent.VK_F); JMenu exportMenu = new JMenu(resourceBundle.getString(RROOT + ".file.export")); exportMenu.setMnemonic(KeyEvent.VK_A); menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.jordan"), KeyEvent.VK_J); menuItem.setToolTipText(resourceBundle.getString(RROOT + ".file.export.jordan.tooltip")); menuItem.setActionCommand(ACTION_EXPORT_JORDAN); menuItem.addActionListener(this); exportMenu.add(menuItem); menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.doug"), KeyEvent.VK_D); menuItem.setToolTipText("For Losers"); menuItem.setActionCommand(ACTION_EXPORT_DOUG); menuItem.addActionListener(this); exportMenu.add(menuItem); exportMenu.addSeparator(); menuItem = new JMenuItem("XML...", KeyEvent.VK_X); menuItem.setActionCommand(ACTION_EXPORT_XML); menuItem.addActionListener(this); exportMenu.add(menuItem); fileMenu.add(exportMenu); if (!OsUtil.isMac()) { fileMenu.addSeparator(); menuItem = new JMenuItem("Exit", KeyEvent.VK_X); menuItem.setActionCommand(ACTION_EXIT); menuItem.addActionListener(this); fileMenu.add(menuItem); } return fileMenu; }
From source file:livecanvas.mesheditor.MeshEditor.java
public JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu, subMenu; JMenuItem menuItem;//from w w w .ja va 2s .c o m menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menu.add(menuItem = Utils.createMenuItem("New", NEW, KeyEvent.VK_N, "ctrl N", this)); menu.add(menuItem = Utils.createMenuItem("Open...", OPEN, KeyEvent.VK_O, "ctrl O", this)); menu.add(menuItem = Utils.createMenuItem("Save", SAVE, KeyEvent.VK_S, "ctrl S", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Exit", EXIT, KeyEvent.VK_X, "", this)); menuBar.add(menu); menu = new JMenu("Edit"); menu.setMnemonic(KeyEvent.VK_E); menu.add(menuItem = Utils.createMenuItem("Undo", UNDO, KeyEvent.VK_U, "ctrl Z", this)); menu.add(menuItem = Utils.createMenuItem("Redo", REDO, KeyEvent.VK_R, "ctrl Y", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Cut", CUT, KeyEvent.VK_T, "ctrl X", this)); menu.add(menuItem = Utils.createMenuItem("Copy", COPY, KeyEvent.VK_C, "ctrl C", this)); menu.add(menuItem = Utils.createMenuItem("Paste", PASTE, KeyEvent.VK_P, "ctrl V", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Select All", SELECT_ALL, KeyEvent.VK_A, "ctrl A", this)); menu.add(menuItem = Utils.createMenuItem("Invert Selection", INVERT_SELECTION, 0, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Settings...", SETTINGS, KeyEvent.VK_S, "", this)); menuBar.add(menu); menu = new JMenu("Tools"); menu.setMnemonic(KeyEvent.VK_T); menu.add(menuItem = Utils.createMenuItem("Brush", TOOLS_BRUSH, KeyEvent.VK_B, "B", this)); menu.add(menuItem = Utils.createMenuItem("Pencil", TOOLS_PEN, KeyEvent.VK_N, "N", this)); menu.add(menuItem = Utils.createMenuItem("Magic Wand", TOOLS_MAGICWAND, KeyEvent.VK_W, "W", this)); menu.add(menuItem = Utils.createMenuItem("Set Control Points", TOOLS_SETCONTROLPOINTS, KeyEvent.VK_C, "C", this)); menu.add(menuItem = Utils.createMenuItem("Pointer", TOOLS_POINTER, KeyEvent.VK_P, "P", this)); menu.add(menuItem = Utils.createMenuItem("Pan / Zoom", TOOLS_PANZOOM, KeyEvent.VK_Z, "Z", this)); menuBar.add(menu); menu = new JMenu("Layers"); menu.setMnemonic(KeyEvent.VK_L); menu.add(menuItem = Utils.createMenuItem("Add Layer...", ADD_LAYER, KeyEvent.VK_A, "", this)); menu.add(menuItem = Utils.createMenuItem("Remove", REMOVE_LAYER, KeyEvent.VK_R, "", this)); menu.add(menuItem = Utils.createMenuItem("Duplicate", DUPLICATE_LAYER, KeyEvent.VK_C, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Move Up", MOVEUP_LAYER, KeyEvent.VK_U, "", this)); menu.add(menuItem = Utils.createMenuItem("Move Down", MOVEDOWN_LAYER, KeyEvent.VK_D, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Reparent Layer...", REPARENT_LAYER, KeyEvent.VK_R, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Group Layers", GROUP_LAYERS, KeyEvent.VK_G, "", this)); menu.add(menuItem = Utils.createMenuItem("Ungroup Layer", UNGROUP_LAYER, KeyEvent.VK_N, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Join Layers", JOIN_LAYERS, KeyEvent.VK_J, "", this)); menu.add(menuItem = Utils.createMenuItem("Intersect", INTERSECT_LAYERS, KeyEvent.VK_I, "", this)); menu.add(menuItem = Utils.createMenuItem("Subtract", SUBTRACT_LAYERS, KeyEvent.VK_S, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Rename...", RENAME_LAYER, KeyEvent.VK_E, "", this)); menu.addSeparator(); subMenu = new JMenu("Background Reference"); subMenu.add(menuItem = Utils.createMenuItem("Set...", BGREF_SET, KeyEvent.VK_S, "", this)); subMenu.add(menuItem = Utils.createMenuItem("Remove", BGREF_REMOVE, KeyEvent.VK_R, "", this)); menu.add(subMenu); menuBar.add(menu); menu.addSeparator(); menu.add(menuItem = Utils.createMenuItem("Create Mesh Grid", CREATE_MESHGRID, KeyEvent.VK_M, "", this)); menu.addSeparator(); menu.add(menuItem = Utils.createCheckBoxMenuItem("See Through", SEE_THROUGH, KeyEvent.VK_T, "", this)); menuItem.setSelected(true); menu.add(menuItem = Utils.createCheckBoxMenuItem("Show Mesh", SHOW_MESH, KeyEvent.VK_M, "", this)); menuItem.setSelected(true); return menuBar; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java
private JMenu createEditMenu() { JMenu edit_menu = new JMenu("Edit"); edit_menu.setMnemonic(KeyEvent.VK_E); edit_menu.add(theActionManager.get("undo")); edit_menu.add(theActionManager.get("redo")); edit_menu.addSeparator();/* w w w . j a v a2s. c om*/ edit_menu.add(theActionManager.get("cut")); edit_menu.add(theActionManager.get("copy")); edit_menu.add(theActionManager.get("delete")); edit_menu.add(theActionManager.get("screenshot")); edit_menu.addSeparator(); edit_menu.add(theActionManager.get("selectall")); edit_menu.add(theActionManager.get("selectnone")); edit_menu.addSeparator(); edit_menu.add(theActionManager.get("enlarge")); edit_menu.add(theActionManager.get("resetsize")); edit_menu.add(theActionManager.get("shrink")); edit_menu.addSeparator(); edit_menu.add(theActionManager.get("group")); edit_menu.add(theActionManager.get("ungroup")); edit_menu.addSeparator(); edit_menu.add(theActionManager.get("placestructures")); return edit_menu; }
From source file:cl.almejo.vsim.gui.SimWindow.java
private JMenu newMenu(String title, int mnemonic, JMenuBar menuBar) { JMenu menu = new JMenu(title); menu.setMnemonic(mnemonic); menuBar.add(menu);/*from w ww.j a va2s. com*/ return menu; }
From source file:JXTransformer.java
public TransformerDemo() { super("Transformer demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu lafMenu = new JMenu("LaF"); JMenuItem winLaf = new JMenuItem("Windows LaF"); lafMenu.add(winLaf);// w ww.j a v a2s .co m winLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } }); JMenuItem motifLaf = new JMenuItem("Motif LaF"); lafMenu.add(motifLaf); motifLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } }); bar.add(lafMenu); JMenuItem metalLaf = new JMenuItem("Metal LaF"); lafMenu.add(metalLaf); metalLaf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setLaf("javax.swing.plaf.metal.MetalLookAndFeel"); } }); JMenu settingsMenu = new JMenu("Settings"); settingsMenu.setMnemonic(KeyEvent.VK_S); JMenuItem item = new JMenuItem("Reset sliders", KeyEvent.VK_R); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rotationSlider.setValue(0); scalingSlider.setValue(100); shearingSlider.setValue(0); } }); settingsMenu.add(item); bar.add(settingsMenu); setJMenuBar(bar); JPanel panel = new JPanel(new BorderLayout()); panel.add(createDemoPanel()); panel.add(createStressTestPanel(), BorderLayout.EAST); add(new JScrollPane(panel)); add(new JScrollPane(createToolPanel()), BorderLayout.SOUTH); pack(); }
From source file:jchrest.gui.Shell.java
private JMenu createShellMenu() { JMenuItem exit = new JMenuItem("Exit", new ImageIcon(Shell.class.getResource("icons/Stop16.gif"))); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0);/*from ww w . j a v a 2 s . c o m*/ } }); JMenu menu = new JMenu("Shell"); menu.setMnemonic(KeyEvent.VK_S); menu.add(new AboutAction(this)); menu.getItem(0).setMnemonic(KeyEvent.VK_A); menu.add(new LookFeelAction(this)); menu.getItem(1).setMnemonic(KeyEvent.VK_T); menu.add(new JSeparator()); menu.add(exit); menu.getItem(3).setMnemonic(KeyEvent.VK_X); menu.getItem(0).setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK, false)); menu.getItem(3).setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false)); return menu; }
From source file:jchrest.gui.Shell.java
private JMenu createModelMenu(int time) { JMenu menu = new JMenu("Model"); menu.setMnemonic(KeyEvent.VK_M); menu.add(new ClearModelAction(this)); menu.getItem(0).setMnemonic(KeyEvent.VK_C); JMenu submenu = new JMenu("Save"); submenu.setMnemonic(KeyEvent.VK_S); submenu.add(new SaveModelAsVnaAction(this, time)); submenu.getItem(0).setMnemonic(KeyEvent.VK_N); submenu.add(new SaveModelSemanticLinksAsVnaAction(this, time)); submenu.getItem(1).setMnemonic(KeyEvent.VK_L); menu.add(submenu);//from w w w.j ava 2 s .c om menu.add(new ModelPropertiesAction(this)); menu.getItem(2).setMnemonic(KeyEvent.VK_P); menu.add(new JSeparator()); menu.add(new ModelInformationAction(this, time)); menu.getItem(4).setMnemonic(KeyEvent.VK_I); menu.add(new ViewModelAction(this)); menu.getItem(5).setMnemonic(KeyEvent.VK_V); return menu; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java
private JMenu createViewMenu() { GraphicOptions view_opt = theCanvas.getWorkspace().getGraphicOptions(); JMenu view_menu = new JMenu("View"); view_menu.setMnemonic(KeyEvent.VK_V); // zoom //from ww w . ja v a 2 s . c o m view_menu.add(theActionManager.get("zoomnone")); view_menu.add(theActionManager.get("zoomin")); view_menu.add(theActionManager.get("zoomout")); view_menu.addSeparator(); // notation JRadioButtonMenuItem last = null; ButtonGroup groupn = new ButtonGroup(); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_CFG))); last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFG)); groupn.add(last); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_CFGBW))); last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFGBW)); groupn.add(last); view_menu.add(last = new JRadioButtonMenuItem( theActionManager.get("notation=" + GraphicOptions.NOTATION_CFGLINK))); last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_CFGLINK)); groupn.add(last); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_UOXF))); last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_UOXF)); groupn.add(last); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("notation=" + GraphicOptions.NOTATION_TEXT))); last.setSelected(view_opt.NOTATION.equals(GraphicOptions.NOTATION_TEXT)); groupn.add(last); view_menu.addSeparator(); // display display_button_group = new ButtonGroup(); display_models = new HashMap<String, ButtonModel>(); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_COMPACT))); last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_COMPACT)); display_models.put(GraphicOptions.DISPLAY_COMPACT, last.getModel()); display_button_group.add(last); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_NORMAL))); last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_NORMAL)); display_models.put(GraphicOptions.DISPLAY_NORMAL, last.getModel()); display_button_group.add(last); view_menu.add(last = new JRadioButtonMenuItem( theActionManager.get("display=" + GraphicOptions.DISPLAY_NORMALINFO))); last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_NORMALINFO)); display_models.put(GraphicOptions.DISPLAY_NORMALINFO, last.getModel()); display_button_group.add(last); view_menu.add( last = new JRadioButtonMenuItem(theActionManager.get("display=" + GraphicOptions.DISPLAY_CUSTOM))); last.setSelected(view_opt.DISPLAY.equals(GraphicOptions.DISPLAY_CUSTOM)); display_models.put(GraphicOptions.DISPLAY_CUSTOM, last.getModel()); display_button_group.add(last); //view_menu.add( lastcb = new JCheckBoxMenuItem(theActionManager.get("showinfo")) ); //lastcb.setState(view_opt.SHOW_INFO); view_menu.addSeparator(); // orientation view_menu.add(theActionManager.get("orientation")); view_menu.addSeparator(); view_menu.add(theActionManager.get("displaysettings")); view_menu.add(theActionManager.get("reportsettings")); return view_menu; }