List of usage examples for javax.swing JMenuItem setMnemonic
@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic") public void setMnemonic(int mnemonic)
From source file:Java2DExample.java
public Java2DExample() { super("Java 2D Image Processing Demo"); imagePanel = new ImagePanel(Java2DExample.class.getResource("yourImage.png")); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar);// w w w. j a v a2 s .c o m filterMenu.setMnemonic('I'); JMenuItem originalMenuItem = new JMenuItem("Display Original"); originalMenuItem.setMnemonic('O'); originalMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent action) { imagePanel.displayOriginalImage(); } }); JMenuItem invertMenuItem = createMenuItem("Invert", 'I', invertFilter); JMenuItem sharpenMenuItem = createMenuItem("Sharpen", 'S', sharpenFilter); JMenuItem blurMenuItem = createMenuItem("Blur", 'B', blurFilter); JMenuItem changeColorsMenuItem = createMenuItem("Change Colors", 'C', colorFilter); filterMenu.add(originalMenuItem); filterMenu.add(invertMenuItem); filterMenu.add(sharpenMenuItem); filterMenu.add(blurMenuItem); filterMenu.add(changeColorsMenuItem); menuBar.add(filterMenu); getContentPane().add(imagePanel, BorderLayout.CENTER); }
From source file:cz.lidinsky.editor.Menu.java
Menu addItem(String text, String actionCommand, ActionListener listener, char mnemonic) { JMenuItem item = new JMenuItem(text); item.setActionCommand(actionCommand); item.addActionListener(listener);/*w ww . j a v a 2 s . co m*/ item.setMnemonic(mnemonic); JMenu lastMenu = getMenu(getMenuCount() - 1); lastMenu.add(item); return this; }
From source file:com.github.rholder.gradle.ui.DependencyViewerStandalone.java
private void initMenu() { JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);//from ww w.jav a 2 s . c om JMenuItem open = new JMenuItem("Open Project Folder", KeyEvent.VK_O); open.setMnemonic(KeyEvent.VK_O); open.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptForGradleBaseDir(); refresh(); } }); fileMenu.add(open); JMenuItem refresh = new JMenuItem("Refresh"); refresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { refresh(); } }); fileMenu.add(refresh); fileMenu.addSeparator(); JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X); exit.setMnemonic(KeyEvent.VK_X); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exit); setJMenuBar(menuBar); }
From source file:MenuTest.java
public MenuFrame() { setTitle("MenuTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); fileMenu.add(new TestAction("New")); // demonstrate accelerators JMenuItem openItem = fileMenu.add(new TestAction("Open")); openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); fileMenu.addSeparator();/* w ww.java 2s. c o m*/ saveAction = new TestAction("Save"); JMenuItem saveItem = fileMenu.add(saveAction); saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); saveAsAction = new TestAction("Save As"); fileMenu.add(saveAsAction); fileMenu.addSeparator(); fileMenu.add(new AbstractAction("Exit") { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // demonstrate check box and radio button menus readonlyItem = new JCheckBoxMenuItem("Read-only"); readonlyItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean saveOk = !readonlyItem.isSelected(); saveAction.setEnabled(saveOk); saveAsAction.setEnabled(saveOk); } }); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert"); insertItem.setSelected(true); JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype"); group.add(insertItem); group.add(overtypeItem); // demonstrate icons Action cutAction = new TestAction("Cut"); cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); Action copyAction = new TestAction("Copy"); copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); Action pasteAction = new TestAction("Paste"); pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); JMenu editMenu = new JMenu("Edit"); editMenu.add(cutAction); editMenu.add(copyAction); editMenu.add(pasteAction); // demonstrate nested menus JMenu optionMenu = new JMenu("Options"); optionMenu.add(readonlyItem); optionMenu.addSeparator(); optionMenu.add(insertItem); optionMenu.add(overtypeItem); editMenu.addSeparator(); editMenu.add(optionMenu); // demonstrate mnemonics JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); JMenuItem indexItem = new JMenuItem("Index"); indexItem.setMnemonic('I'); helpMenu.add(indexItem); // you can also add the mnemonic key to an action Action aboutAction = new TestAction("About"); aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A')); helpMenu.add(aboutAction); // add all top-level menus to menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); // demonstrate pop-ups popup = new JPopupMenu(); popup.add(cutAction); popup.add(copyAction); popup.add(pasteAction); JPanel panel = new JPanel(); panel.setComponentPopupMenu(popup); add(panel); // the following line is a workaround for bug 4966109 panel.addMouseListener(new MouseAdapter() { }); }
From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java
private JMenu createFileMenu() { JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('f'); JMenuItem fileExit = new JMenuItem("Exit"); fileExit.setMnemonic('x'); fileExit.setActionCommand("exit"); fileExit.addActionListener(actionMapper); fileMenu.add(fileExit);/*from ww w. ja v a 2 s .co m*/ return fileMenu; }
From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
private JMenuItem createAddCatMenuItem() { JMenuItem item = new JMenuItem("Add new"); item.setMnemonic('n'); item.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADD)); item.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCategory();//from www . j av a 2s. c om } }); return item; }
From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
private JMenu buildCategoryMenu() { JMenu categoryMenu = new JMenu("Categories"); categoryMenu.setMnemonic('t'); JMenuItem showItem = new JMenuItem("Show"); showItem.setMnemonic('s'); JMenuItem addCatButton = createAddCatMenuItem(); showItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCategoriesNode()); }// w w w.j a v a 2s. c o m }); categoryMenu.add(showItem); categoryMenu.addSeparator(); categoryMenu.add(addCatButton); return categoryMenu; }
From source file:MenuDemo.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu("File"); menuFile.setMnemonic('f'); JMenuItem menuItem = new JMenuItem("New"); menuItem.setIcon(new ImageIcon("file_new.gif")); menuItem.setMnemonic('n'); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("New"); }// w w w . j av a 2s.com }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Open..."); menuItem.setIcon(new ImageIcon("file_open.gif")); menuItem.setMnemonic('o'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { MenuDemo.this.repaint(); if (fileChooser.showOpenDialog(MenuDemo.this) != JFileChooser.APPROVE_OPTION) return; System.out.println(fileChooser.getSelectedFile()); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuItem = new JMenuItem("Save..."); menuItem.setIcon(new ImageIcon("file_save.gif")); menuItem.setMnemonic('s'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Save..."); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuFile.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.setMnemonic('x'); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; menuItem.addActionListener(lst); menuFile.add(menuItem); menuBar.add(menuFile); ActionListener fontListener = new ActionListener() { public void actionPerformed(ActionEvent e) { updateMonitor(); } }; JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); menus = new JMenuItem[FontNames.length]; for (int i = 0; i < FontNames.length; i++) { int m = i + 1; menus[i] = new JRadioButtonMenuItem(m + " " + FontNames[i]); boolean selected = (i == 0); menus[i].setSelected(selected); menus[i].setMnemonic('1' + i); menus[i].setFont(fontArray[i]); menus[i].addActionListener(fontListener); group.add(menus[i]); mFont.add(menus[i]); } mFont.addSeparator(); boldMenuItem = new JCheckBoxMenuItem("Bold"); boldMenuItem.setMnemonic('b'); Font fn = fontArray[1].deriveFont(Font.BOLD); boldMenuItem.setFont(fn); boldMenuItem.setSelected(false); boldMenuItem.addActionListener(fontListener); mFont.add(boldMenuItem); italicMenuItem = new JCheckBoxMenuItem("Italic"); italicMenuItem.setMnemonic('i'); fn = fontArray[1].deriveFont(Font.ITALIC); italicMenuItem.setFont(fn); italicMenuItem.setSelected(false); italicMenuItem.addActionListener(fontListener); mFont.add(italicMenuItem); menuBar.add(mFont); return menuBar; }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JMenu buildResultsMenu() { JMenu resultsMenu = new JMenu("Results"); resultsMenu.setMnemonic('r'); JMenuItem cwItem = new JMenuItem("Central weight vectors", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CENTRALWEIGHTS)); cwItem.setMnemonic('c'); JMenuItem racsItem = new JMenuItem("Rank acceptability indices", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES)); racsItem.setMnemonic('r'); cwItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCentralWeightsNode()); }// w ww.ja v a 2 s . c o m }); racsItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getRankAcceptabilitiesNode()); } }); resultsMenu.add(cwItem); resultsMenu.add(racsItem); return resultsMenu; }
From source file:misc.TextBatchPrintingDemo.java
/** * Create and return a menu item with the specified action, mnemonics and * keyboad accelerator./*ww w.j a v a 2 s .c om*/ */ JMenuItem createMenuItem(Action action, int mnemonics, KeyStroke accel) { JMenuItem item = new JMenuItem(action); item.setMnemonic(mnemonics); item.setAccelerator(accel); return item; }