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:FramewithMenuShortcut.java
public FramewithMenuShortcut(String title) { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);//from ww w.j av a 2 s .c o m newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:MainClass.java
public MainClass() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/*from w ww . j a v a 2s .c o m*/ JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); // Construct the file pull down menu newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); JMenu colorMenu = new JMenu("Color"); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); newItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK)); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); elementMenu.add(curveItem = new JRadioButtonMenuItem("Curve", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); types.add(curveItem); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', Event.CTRL_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', Event.CTRL_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); curveItem.setAccelerator(KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); elementMenu.addSeparator(); elementMenu.add(colorMenu); // Add the sub-menu colorMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); colorMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); colorMenu.add(greenItem = new JCheckBoxMenuItem("Green", false)); colorMenu.add(blueItem = new JCheckBoxMenuItem("Blue", true)); // Add element color accelerators redItem.setAccelerator(KeyStroke.getKeyStroke('R', Event.CTRL_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', Event.CTRL_MASK)); greenItem.setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK)); blueItem.setAccelerator(KeyStroke.getKeyStroke('B', Event.CTRL_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/* w ww. j av a2 s .com*/ JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); // Construct the file pull down menu newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); JMenu colorMenu = new JMenu("Color"); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); newItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', Event.CTRL_MASK)); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); elementMenu.add(curveItem = new JRadioButtonMenuItem("Curve", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); types.add(curveItem); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', Event.CTRL_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', Event.CTRL_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', Event.CTRL_MASK)); curveItem.setAccelerator(KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); elementMenu.addSeparator(); elementMenu.add(colorMenu); // Add the sub-menu colorMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); colorMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); colorMenu.add(greenItem = new JCheckBoxMenuItem("Green", false)); colorMenu.add(blueItem = new JCheckBoxMenuItem("Blue", true)); // Add element color accelerators redItem.setAccelerator(KeyStroke.getKeyStroke('R', Event.CTRL_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', Event.CTRL_MASK)); greenItem.setAccelerator(KeyStroke.getKeyStroke('G', Event.CTRL_MASK)); blueItem.setAccelerator(KeyStroke.getKeyStroke('B', Event.CTRL_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:Main.java
public FramewithMenuShortcut() { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/*www . j a v a 2 s . c o m*/ newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:uk.co.petertribble.jkstat.demo.JLoadChart.java
/** * A standalone demo charting load averages. *//*from w w w. ja va2 s . co m*/ public JLoadChart() { super("JLoadChart"); jkstat = new NativeJKstat(); int maxage = 600000; String lavetext = KstatResources.getString("LOAD.AVERAGE.TEXT"); ts1 = new TimeSeries("1min " + lavetext); ts1.setMaximumItemAge(maxage); ts5 = new TimeSeries("5min " + lavetext); ts5.setMaximumItemAge(maxage); ts15 = new TimeSeries("15min " + lavetext); ts15.setMaximumItemAge(maxage); updateAccessory(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(ts1); dataset.addSeries(ts5); dataset.addSeries(ts15); JFreeChart chart = ChartFactory.createTimeSeriesChart(lavetext, KstatResources.getString("CHART.TIME"), KstatResources.getString("LOAD.LOAD.TEXT"), dataset, true, true, false); XYPlot xyplot = chart.getXYPlot(); NumberAxis loadaxis = new NumberAxis(KstatResources.getString("LOAD.LOAD.TEXT")); loadaxis.setAutoRange(true); loadaxis.setAutoRangeIncludesZero(true); xyplot.setRangeAxis(loadaxis); DateAxis daxis = new DateAxis(KstatResources.getString("CHART.TIME")); daxis.setAutoRange(true); daxis.setFixedAutoRange(maxage); xyplot.setDomainAxis(daxis); addWindowListener(new winExit()); setContentPane(new ChartPanel(chart)); JMenuBar jm = new JMenuBar(); JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); exitItem = new JMenuItem(KstatResources.getString("FILE.EXIT.TEXT"), KeyEvent.VK_X); exitItem.addActionListener(this); jme.add(exitItem); jm.add(jme); setJMenuBar(jm); pack(); setVisible(true); Timer timer = new Timer(5000, this); timer.start(); }
From source file:InternalFrameDemo.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); // Set up the lone menu. JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu);/*w ww. j a v a2 s . c o m*/ // Set up the first menu item. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); // Set up the second menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; }
From source file:com.github.pemapmodder.pocketminegui.gui.server.ServerMainActivity.java
@Override protected void onStart() { lifetime = new ServerLifetime(this); // setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); setLayout(new GridBagLayout()); JMenuBar bar = new JMenuBar(); JMenu serverMenu = new JMenu("Server"); serverMenu.setMnemonic(KeyEvent.VK_S); JMenu playerMenu = new JMenu("Players"); playerMenu.setMnemonic(KeyEvent.VK_P); bar.add(serverMenu);/*w ww . j ava2 s . c om*/ bar.add(playerMenu); setJMenuBar(bar); startStopButton = new JButton("Start"); startStopButton.addActionListener(lifetime::listen); GridBagConstraints constr = new GridBagConstraints(); constr.gridx = 0; constr.gridy = 0; constr.fill = GridBagConstraints.VERTICAL; constr.weighty = 0.02; constr.weightx = 0.1; add(startStopButton, constr); constr.gridx = 1; constr.gridy = 1; constr.fill = GridBagConstraints.BOTH; constr.weightx = 0.8; constr.weighty = 0.9; add(consolePanel = new ConsolePanel(this), constr); }
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 w ww .j a v a2 s . co m*/ 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:ToolbarDemo.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu mFile = new JMenu("File"); mFile.setMnemonic('f'); ImageIcon iconNew = new ImageIcon("file_new.gif"); Action actionNew = new AbstractAction("New", iconNew) { public void actionPerformed(ActionEvent e) { System.out.println("new action"); }/*from www. j a v a2 s. c om*/ }; JMenuItem item = mFile.add(actionNew); mFile.add(item); ImageIcon iconOpen = new ImageIcon("file_open.gif"); Action actionOpen = new AbstractAction("Open...", iconOpen) { public void actionPerformed(ActionEvent e) { System.out.println("open action"); } }; item = mFile.add(actionOpen); mFile.add(item); ImageIcon iconSave = new ImageIcon("file_save.gif"); Action actionSave = new AbstractAction("Save...", iconSave) { public void actionPerformed(ActionEvent e) { System.out.println("save action"); } }; item = mFile.add(actionSave); mFile.add(item); mFile.addSeparator(); Action actionExit = new AbstractAction("Exit") { public void actionPerformed(ActionEvent e) { System.exit(0); } }; item = mFile.add(actionExit); item.setMnemonic('x'); menuBar.add(mFile); toolBar = new JToolBar(); JButton btn1 = toolBar.add(actionNew); btn1.setToolTipText("New text"); JButton btn2 = toolBar.add(actionOpen); btn2.setToolTipText("Open text file"); JButton btn3 = toolBar.add(actionSave); btn3.setToolTipText("Save text file"); ActionListener fontListener = new ActionListener() { public void actionPerformed(ActionEvent e) { updateMonitor(); } }; JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); fontMenus = new JMenuItem[FontNames.length]; for (int k = 0; k < FontNames.length; k++) { int m = k + 1; fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontNames[k]); boolean selected = (k == 0); fontMenus[k].setSelected(selected); fontMenus[k].setMnemonic('1' + k); fontMenus[k].setFont(fonts[k]); fontMenus[k].addActionListener(fontListener); group.add(fontMenus[k]); mFont.add(fontMenus[k]); } mFont.addSeparator(); boldMenu.setMnemonic('b'); Font fn = fonts[1].deriveFont(Font.BOLD); boldMenu.setFont(fn); boldMenu.setSelected(false); boldMenu.addActionListener(fontListener); mFont.add(boldMenu); italicMenu.setMnemonic('i'); fn = fonts[1].deriveFont(Font.ITALIC); italicMenu.setFont(fn); italicMenu.setSelected(false); italicMenu.addActionListener(fontListener); mFont.add(italicMenu); menuBar.add(mFont); getContentPane().add(toolBar, BorderLayout.NORTH); 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()); }//from w ww.ja v a2 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; }