Java Code Examples for javax.swing.JMenuItem#setMnemonic()
The following examples show how to use
javax.swing.JMenuItem#setMnemonic() .
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: AbstractMenuFactory.java From netbeans with Apache License 2.0 | 6 votes |
private void configureMenuItem (JMenuItem item, String containerCtx, String action, ActionProvider provider, Map context) { // System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action); item.setName(action); item.putClientProperty(KEY_ACTION, action); item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx); item.putClientProperty(KEY_CREATOR, this); item.setText( provider.getDisplayName(action, containerCtx)); // System.err.println(" item text is " + item.getText()); item.setToolTipText(provider.getDescription(action, containerCtx)); int state = context == null ? ActionProvider.STATE_ENABLED | ActionProvider.STATE_VISIBLE : provider.getState (action, containerCtx, context); boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0; // System.err.println("action " + action + (enabled ? " enabled" : " disabled")); item.setEnabled(enabled); boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0; // System.err.println("action " + action + (visible ? " visible" : " invisible")); item.setVisible(visible); item.setMnemonic(provider.getMnemonic(action, containerCtx)); item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(action, containerCtx)); item.setIcon(provider.getIcon(action, containerCtx, BeanInfo.ICON_COLOR_16x16)); }
Example 2
Source File: NbEditorKit.java From netbeans with Apache License 2.0 | 6 votes |
private static void assignAccelerator(Keymap km, Action action, JMenuItem item) { if (item.getAccelerator() == null){ KeyStroke ks = (KeyStroke)action.getValue(Action.ACCELERATOR_KEY); if (ks!=null) { item.setMnemonic(ks.getKeyCode()); } else { // Try to get the accelerator from keymap if (km != null) { KeyStroke[] keys = km.getKeyStrokesForAction(action); if (keys != null && keys.length > 0) { item.setMnemonic(keys[0].getKeyCode()); } } } } }
Example 3
Source File: NbEditorKit.java From netbeans with Apache License 2.0 | 6 votes |
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){ // Try to get the accelerator Keymap km = (target == null) ? BaseKit.getKit(BaseKit.class).getKeymap() : target.getKeymap(); if (km != null) { KeyStroke[] keys = km.getKeyStrokesForAction(a); if (keys != null && keys.length > 0) { boolean added = false; for (int i = 0; i<keys.length; i++){ if ((keys[i].getKeyCode() == KeyEvent.VK_MULTIPLY) || keys[i].getKeyCode() == KeyEvent.VK_ADD){ item.setMnemonic(keys[i].getKeyCode()); added = true; break; } } if (added == false) item.setMnemonic(keys[0].getKeyCode()); } } }
Example 4
Source File: MainFrame.java From sc2gears with Apache License 2.0 | 6 votes |
/** * Rebuilds the recent replays menu. */ private void rebuildRecentReplaysMenu() { recentReplaysMenu.removeAll(); final int recentReplaysCount = Settings.getInt( Settings.KEY_RECENT_REPLAYS_COUNT ); for ( int i = 0; i < recentReplaysCount; i++ ) { final File file = new File( Settings.getString( Settings.KEY_RECENT_REPLAY_ENTRIES + i ) ); final JMenuItem recentReplayMenuItem = new JMenuItem( (i+1) + " " + file.getName(), Icons.CHART ); if ( i < 9 ) recentReplayMenuItem.setMnemonic( '1' + i ); recentReplayMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed( final ActionEvent event ) { openReplayFile( file ); } } ); recentReplaysMenu.add( recentReplayMenuItem ); } }
Example 5
Source File: TabsMenu.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void menuSelected(MenuEvent e) { TabsMenu.this.removeAll(); ExploreNodeAction exploreAction = new ExploreNodeAction(cliGuiCtx); JMenuItem exploreSelectedNode = new JMenuItem(exploreAction); exploreSelectedNode.setMnemonic(KeyEvent.VK_E); if ((exploreAction.getSelectedNode() == null) || exploreAction.getSelectedNode().isLeaf()) { exploreSelectedNode.setEnabled(false); } add(exploreSelectedNode); addSeparator(); JTabbedPane tabs = cliGuiCtx.getTabs(); for (int i=0; i < tabs.getTabCount(); i++) { GoToTabAction action = new GoToTabAction(i, tabs.getTitleAt(i)); JMenuItem item = new JMenuItem(action); item.setToolTipText(tabs.getToolTipTextAt(i)); add(item); } }
Example 6
Source File: GameMenu.java From triplea with GNU General Public License v3.0 | 5 votes |
private void addEditMode() { final JCheckBoxMenuItem editMode = new JCheckBoxMenuItem("Enable Edit Mode"); editMode.setModel(frame.getEditModeButtonModel()); final JMenuItem editMenuItem = add(editMode); editMenuItem.setMnemonic(KeyEvent.VK_E); editMenuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); }
Example 7
Source File: FileMenu.java From triplea with GNU General Public License v3.0 | 5 votes |
private void addExitMenu() { final boolean isMac = SystemProperties.isMac(); final JMenuItem leaveGameMenuExit = new JMenuItem(SwingAction.of("Leave Game", e -> frame.leaveGame())); leaveGameMenuExit.setMnemonic(KeyEvent.VK_L); if (isMac) { // On Mac OS X, the command-Q is reserved for the Quit action, // so set the command-L key combo for the Leave Game action leaveGameMenuExit.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); } else { // On non-Mac operating systems, set the Ctrl-Q key combo for the Leave Game action leaveGameMenuExit.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); } add(leaveGameMenuExit); // Mac OS X automatically creates a Quit menu item under the TripleA menu, // so all we need to do is register that menu item with triplea's shutdown mechanism if (isMac) { MacOsIntegration.setQuitHandler(frame); } else { // On non-Mac operating systems, we need to manually create an Exit menu item final JMenuItem menuFileExit = new JMenuItem(SwingAction.of("Exit Program", e -> frame.shutdown())); menuFileExit.setMnemonic(KeyEvent.VK_E); add(menuFileExit); } }
Example 8
Source File: SwingSet2.java From beautyeye with Apache License 2.0 | 5 votes |
/** * Creates a JMenuItem for the Look and Feel popup menu. * * @param menu the menu * @param label the label * @param mnemonic the mnemonic * @param accessibleDescription the accessible description * @param laf the laf * @return the j menu item */ public JMenuItem createPopupMenuItem(JPopupMenu menu, String label, String mnemonic, String accessibleDescription, String laf) { JMenuItem mi = menu.add(new JMenuItem(getString(label))); popupMenuGroup.add(mi); mi.setMnemonic(getMnemonic(mnemonic)); mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription)); // mi.addActionListener(new ChangeLookAndFeelAction(this, laf)); // mi.setEnabled(isAvailableLookAndFeel(laf)); return mi; }
Example 9
Source File: QFixMessengerFrame.java From quickfix-messenger with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initWindowMenu() { windowMenu = new JMenu("Window"); windowMenu.setMnemonic('W'); JMenuItem projectWindowMenuItem = new JMenuItem("Project Window"); JMenuItem logfileWindowMenuItem = new JMenuItem("Logfile Window"); projectWindowMenuItem.setIcon(IconBuilder.build(getMessenger() .getConfig(), IconBuilder.WINDOW_ICON)); projectWindowMenuItem.setMnemonic('P'); projectWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); projectWindowMenuItem .addActionListener(new ProjectWindowActionListener(this)); logfileWindowMenuItem.setIcon(IconBuilder.build(getMessenger() .getConfig(), IconBuilder.WINDOW_ICON)); logfileWindowMenuItem.setMnemonic('L'); logfileWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK)); logfileWindowMenuItem .addActionListener(new LogfileWindowActionListener(this)); windowMenu.add(logfileWindowMenuItem); windowMenu.add(projectWindowMenuItem); }
Example 10
Source File: JMenuItemBuilder.java From triplea with GNU General Public License v3.0 | 5 votes |
private void buildImpl(final JMenuItem menuItem) { Preconditions.checkNotNull(actionListener); menuItem.setMnemonic(mnemonic.getInputEventCode()); menuItem.addActionListener(e -> actionListener.run()); Optional.ofNullable(acceleratorKey) .ifPresent( accelerator -> menuItem.setAccelerator( KeyStroke.getKeyStroke( accelerator, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()))); }
Example 11
Source File: MainFrame.java From android-screen-monitor with Apache License 2.0 | 5 votes |
private void initializeAbout() { JMenuItem menuItemAbout = new JMenuItem("About ASM"); menuItemAbout.setMnemonic(KeyEvent.VK_A); menuItemAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { about(); } }); mPopupMenu.add(menuItemAbout); }
Example 12
Source File: Hiero.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initializeMenus () { { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); { JMenu fileMenu = new JMenu(); menuBar.add(fileMenu); fileMenu.setText("File"); fileMenu.setMnemonic(KeyEvent.VK_F); { openMenuItem = new JMenuItem("Open Hiero settings file..."); openMenuItem.setMnemonic(KeyEvent.VK_O); openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); fileMenu.add(openMenuItem); } { saveMenuItem = new JMenuItem("Save Hiero settings file..."); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); fileMenu.add(saveMenuItem); } fileMenu.addSeparator(); { saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)..."); saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B); saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); fileMenu.add(saveBMFontMenuItem); } fileMenu.addSeparator(); { exitMenuItem = new JMenuItem("Exit"); exitMenuItem.setMnemonic(KeyEvent.VK_X); fileMenu.add(exitMenuItem); } } } }
Example 13
Source File: HelpMenu.java From triplea with GNU General Public License v3.0 | 5 votes |
private void addUnitHelpMenu() { final String unitHelpTitle = "Unit Help"; final JMenuItem unitMenuItem = add( SwingAction.of( unitHelpTitle, e -> { final Result<String> result = Interruptibles.awaitResult( () -> BackgroundTaskRunner.runInBackgroundAndReturn( "Calculating Data", () -> getUnitStatsTable(gameData, uiContext))); final JEditorPane editorPane = new JEditorPane( "text/html", result.result.orElse("Failed to calculate Data")); editorPane.setEditable(false); editorPane.setCaretPosition(0); final JScrollPane scroll = new JScrollPane(editorPane); scroll.setBorder(BorderFactory.createEmptyBorder()); createInformationDialog(scroll, unitHelpTitle).setVisible(true); })); unitMenuItem.setMnemonic(KeyEvent.VK_U); unitMenuItem.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); }
Example 14
Source File: PCGenMenuBar.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected JMenuItem createMenuItem(File item, int index) { JMenuItem menuItem = new JMenuItem(); menuItem.setText((index + 1) + " " + item.getName()); //$NON-NLS-1$ menuItem.setToolTipText(item.getAbsolutePath()); menuItem.setActionCommand(item.getAbsolutePath()); menuItem.setMnemonic(String.valueOf(index + 1).charAt(0)); menuItem.addActionListener(this); return menuItem; }
Example 15
Source File: OurUtil.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Construct a new JMenuItem then add it to an existing JMenu. * * @param parent - the JMenu to add this JMenuItem into (or null if you don't * want to add it to any JMenu yet) * @param label - the text to show on the menu * @param attrs - a list of attributes to apply onto the new JMenuItem * <p> * If one positive number a is supplied, we call setMnemonic(a) * <p> * If two positive numbers a and b are supplied, and a!=VK_ALT, and * a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b) * <p> * If two positive numbers a and b are supplied, and a==VK_ALT or * a==VK_SHIFT, we call setAccelerator(a | b) * <p> * If an ActionListener is supplied, we call addActionListener(x) * <p> * If an Boolean x is supplied, we call setEnabled(x) * <p> * If an Icon x is supplied, we call setIcon(x) */ public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) { JMenuItem m = new JMenuItem(label, null); int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); boolean hasMnemonic = false; for (Object x : attrs) { if (x instanceof Character || x instanceof Integer) { int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue(); if (k < 0) continue; if (k == KeyEvent.VK_ALT) { hasMnemonic = true; accelMask = accelMask | InputEvent.ALT_MASK; continue; } if (k == KeyEvent.VK_SHIFT) { hasMnemonic = true; accelMask = accelMask | InputEvent.SHIFT_MASK; continue; } if (!hasMnemonic) { m.setMnemonic(k); hasMnemonic = true; } else m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask)); } if (x instanceof ActionListener) m.addActionListener((ActionListener) x); if (x instanceof Icon) m.setIcon((Icon) x); if (x instanceof Boolean) m.setEnabled((Boolean) x); } if (parent != null) parent.add(m); return m; }
Example 16
Source File: NbEditorKit.java From netbeans with Apache License 2.0 | 5 votes |
private static void addAcceleretors(Action a, JMenuItem item, JTextComponent target) { // Try to get the accelerator Keymap km = (target == null) ? BaseKit.getKit(BaseKit.class).getKeymap() : target.getKeymap(); if (km != null) { KeyStroke[] keys = km.getKeyStrokesForAction(a); if (keys != null && keys.length > 0) { boolean added = false; for (int i = 0; i<keys.length; i++){ if ((keys[i].getKeyCode() == KeyEvent.VK_MULTIPLY) || keys[i].getKeyCode() == KeyEvent.VK_ADD){ item.setMnemonic(keys[i].getKeyCode()); added = true; break; } } if (added == false) { item.setMnemonic(keys[0].getKeyCode()); } }else if (a!=null){ KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY); if (ks!=null) { item.setMnemonic(ks.getKeyCode()); } } } }
Example 17
Source File: MainFrame.java From android-screen-monitor with Apache License 2.0 | 5 votes |
private void initializeSelectDeviceMenu() { JMenuItem menuItemSelectDevice = new JMenuItem("Select Device..."); menuItemSelectDevice.setMnemonic(KeyEvent.VK_D); menuItemSelectDevice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectDevice(); } }); mPopupMenu.add(menuItemSelectDevice); }
Example 18
Source File: GameMenu.java From triplea with GNU General Public License v3.0 | 4 votes |
private void addMenuItemWithHotkey(final Action action, final int keyCode) { final JMenuItem gameMenuItem = add(action); gameMenuItem.setMnemonic(keyCode); gameMenuItem.setAccelerator( KeyStroke.getKeyStroke(keyCode, Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx())); }
Example 19
Source File: ImageViewer.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
/** Constructs an image viewer. */ public ImageViewer(final Context context) { super(TITLE); context.inject(this); setDefaultCloseOperation(DISPOSE_ON_CLOSE); addWindowListener(this); // content pane pane = new JPanel(); pane.setLayout(new BorderLayout()); setContentPane(pane); setSize(350, 350); // default size // navigation sliders sliderPanel = new JPanel(); sliderPanel.setVisible(false); sliderPanel.setBorder(new EmptyBorder(5, 3, 5, 3)); sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.Y_AXIS)); pane.add(BorderLayout.SOUTH, sliderPanel); final JPanel nPanel = new JPanel(); nPanel.setLayout(new BoxLayout(nPanel, BoxLayout.X_AXIS)); sliderPanel.add(nPanel); sliderPanel.add(Box.createVerticalStrut(2)); nSlider = new JSlider(1, 1); nSlider.setEnabled(false); nSlider.addChangeListener(this); nPanel.add(new JLabel("N")); nPanel.add(Box.createHorizontalStrut(3)); nPanel.add(nSlider); final JPanel ztcPanel = new JPanel(); ztcPanel.setLayout(new BoxLayout(ztcPanel, BoxLayout.X_AXIS)); sliderPanel.add(ztcPanel); // image icon final BufferedImage dummy = AWTImageTools.makeImage(new byte[1][1], 1, 1, false); icon = new ImageIcon(dummy); iconLabel = new JLabel(icon, SwingConstants.LEFT); iconLabel.setVerticalAlignment(SwingConstants.TOP); pane.add(new JScrollPane(iconLabel)); // cursor probe probeLabel = new JLabel(" "); probeLabel.setHorizontalAlignment(SwingConstants.CENTER); probeLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); pane.add(BorderLayout.NORTH, probeLabel); iconLabel.addMouseMotionListener(this); // menu bar final JMenuBar menubar = new JMenuBar(); // FIXME: currently the menu bar is disabled to restrict the use of // ImageViewer to the Show command. We could attempt to get this // implementation working nicely, or just convert to an IJ2 // implementation. // setJMenuBar(menubar); final JMenu file = new JMenu("File"); file.setMnemonic('f'); menubar.add(file); final JMenuItem fileOpen = new JMenuItem("Open..."); fileOpen.setMnemonic('o'); fileOpen.setActionCommand("open"); fileOpen.addActionListener(this); file.add(fileOpen); fileSave = new JMenuItem("Save..."); fileSave.setMnemonic('s'); fileSave.setEnabled(false); fileSave.setActionCommand("save"); fileSave.addActionListener(this); file.add(fileSave); fileView = new JMenuItem("View Metadata..."); final JMenuItem fileExit = new JMenuItem("Exit"); fileExit.setMnemonic('x'); fileExit.setActionCommand("exit"); fileExit.addActionListener(this); file.add(fileExit); final JMenu options = new JMenu("Options"); options.setMnemonic('p'); menubar.add(options); final JMenuItem optionsFPS = new JMenuItem("Frames per Second..."); optionsFPS.setMnemonic('f'); optionsFPS.setActionCommand("fps"); optionsFPS.addActionListener(this); options.add(optionsFPS); final JMenu help = new JMenu("Help"); help.setMnemonic('h'); menubar.add(help); final JMenuItem helpAbout = new JMenuItem("About..."); helpAbout.setMnemonic('a'); helpAbout.setActionCommand("about"); helpAbout.addActionListener(this); help.add(helpAbout); // add key listener to focusable components nSlider.addKeyListener(this); }
Example 20
Source File: GoGuiMenuBar.java From FancyBing with GNU General Public License v3.0 | 4 votes |
public void setPrograms(ArrayList<Program> programs) { m_menuAttach.setEnabled(! programs.isEmpty()); for (int i = 0; i < m_programItems.size(); ++i) m_menuAttach.remove(m_programItems.get(i)); if (programs.isEmpty()) return; for (int i = 0; i < programs.size(); ++i) { Program program = programs.get(i); String[] mnemonicArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; String text; String mnemonic; if (! Platform.isMac() && i < mnemonicArray.length) { mnemonic = mnemonicArray[i]; text = mnemonic + ": " + program.m_label; } else { mnemonic = ""; text = program.m_label; } JMenuItem item = new JMenuItem(text); if (! mnemonic.equals("")) { KeyStroke keyStroke = KeyStroke.getKeyStroke(mnemonic); int code = keyStroke.getKeyCode(); item.setMnemonic(code); } final int index = i; item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { m_listener.actionAttachProgram(index); } }); StringBuilder toolTip = new StringBuilder(128); if (program.m_name != null) toolTip.append(program.m_name); if (program.m_version != null && ! program.m_version.equals("") && program.m_version.length() < 40) { toolTip.append(' '); toolTip.append(program.m_version); } if (program.m_command != null) { toolTip.append(" ("); toolTip.append(program.m_command); toolTip.append(')'); } item.setToolTipText(toolTip.toString()); m_menuAttach.add(item); m_programItems.add(item); } }