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:Main.java
/** * Convenience method for creating a JMenu * @param text the menu title/*from ww w.j a va 2 s .c o m*/ * @param mnemonic the mnemonic for the menu * @return a new JMenu with the given title and mnemonic */ public static JMenu menu(String text, char mnemonic) { final JMenu menu = new JMenu(text); menu.setMnemonic(mnemonic); return menu; }
From source file:Main.java
static public JMenu createJMenu(JMenuBar pMenuBar, String pMenuText, char pMnemonic) { final JMenu menu = new JMenu(pMenuText); menu.setMnemonic(pMnemonic); if (defaultFont != null) menu.setFont(defaultFont);/*w w w. j a va2s .c o m*/ pMenuBar.add(menu); return menu; }
From source file:Main.java
/** * Makes a new top-level menu.// w ww. jav a 2s . c o m * * @param items * An array of its child menu items. * @param name * The name of the menu. * @param description * The accessible description. * @param mnemonic * The key (when pressed with Alt) that activates the menu. * @return A properly-initialized new menu. */ public static JMenu createMenu(JMenuItem[] items, String name, String description, int mnemonic) { JMenu menu = new JMenu(name); menu.getAccessibleContext().setAccessibleDescription(description); menu.setMnemonic(mnemonic); addAll(items, menu); return menu; }
From source file:Main.java
public JMenuBar createMenuBar() { JMenuBar top_menu_bar = new JMenuBar(); JMenu main_menu = new JMenu("Menu"); main_menu.setMnemonic(KeyEvent.VK_M); top_menu_bar.add(main_menu);//from w ww . j a v a2s . c o m JMenuItem menu_item; menu_item = new JMenuItem("Add New"); menu_item.setMnemonic(KeyEvent.VK_N); menu_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menu_item.setActionCommand("new"); menu_item.addActionListener(e -> createThumb()); main_menu.add(menu_item); return top_menu_bar; }
From source file:Main.java
protected JMenuBar createMenuBar() { final JMenuBar menuBar = new JMenuBar(); JMenu mFont = new JMenu("Font"); mFont.setMnemonic('o'); ButtonGroup group = new ButtonGroup(); fontMenus = new JMenuItem[FontName.length]; for (int k = 0; k < FontName.length; k++) { int m = k + 1; fontMenus[k] = new JRadioButtonMenuItem(m + " " + FontName[k]); boolean selected = (k == 0); fontMenus[k].setSelected(selected); fontMenus[k].setMnemonic('1' + k); fontMenus[k].setFont(fonts[k]);/*from ww w .ja v a2 s .c o m*/ fontMenus[k].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println(((JComponent) arg0.getSource()).getFont()); } }); group.add(fontMenus[k]); mFont.add(fontMenus[k]); } menuBar.add(mFont); return menuBar; }
From source file:MenuAcceleratorKeyStroke.java
public MenuAcceleratorKeyStroke() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); menu.setMnemonic('f'); bar.add(menu);//from w w w.ja va2 s . c o m JMenuItem exit = new JMenuItem("Exit"); exit.setMnemonic('x'); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Exit performed"); MenuAcceleratorKeyStroke.this.dispose(); System.exit(0); } }); menu.add(exit); menu = new JMenu("Edit"); menu.setMnemonic('e'); bar.add(menu); EditListener l = new EditListener(); JMenuItem mi; mi = menu.add(new JMenuItem("Cut", 't')); mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); mi.addActionListener(l); mi = menu.add(new JMenuItem("Copy", 'c')); mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); mi.addActionListener(l); mi = menu.add(new JMenuItem("Paste", 'p')); mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); mi.addActionListener(l); setJMenuBar(bar); getContentPane().add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:MainClass.java
public MainClass() { menuBar = new JMenuBar(); JMenu formatMenu = new JMenu("Justify"); formatMenu.setMnemonic('J'); MenuAction leftJustifyAction = new MenuAction("Left", new ImageIcon("left.gif")); MenuAction rightJustifyAction = new MenuAction("Right", new ImageIcon("right.gif")); MenuAction centerJustifyAction = new MenuAction("Center", new ImageIcon("center.gif")); MenuAction fullJustifyAction = new MenuAction("Full", new ImageIcon("full.gif")); JMenuItem item;/*from www . j a v a2s . c o m*/ item = formatMenu.add(leftJustifyAction); item.setMnemonic('L'); item = formatMenu.add(rightJustifyAction); item.setMnemonic('R'); item = formatMenu.add(centerJustifyAction); item.setMnemonic('C'); item = formatMenu.add(fullJustifyAction); item.setMnemonic('F'); menuBar.add(formatMenu); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); }
From source file:MenuExample.java
public MenuExample() { menuBar = new JMenuBar(); JMenu formatMenu = new JMenu("Justify"); formatMenu.setMnemonic('J'); MenuAction leftJustifyAction = new MenuAction("Left", new ImageIcon("1.gif")); MenuAction rightJustifyAction = new MenuAction("Right", new ImageIcon("2.gif")); MenuAction centerJustifyAction = new MenuAction("Center", new ImageIcon("3.gif")); MenuAction fullJustifyAction = new MenuAction("Full", new ImageIcon("4.gif")); JMenuItem item;/*w ww . ja v a 2 s . c o m*/ item = formatMenu.add(leftJustifyAction); item.setMnemonic('L'); item = formatMenu.add(rightJustifyAction); item.setMnemonic('R'); item = formatMenu.add(centerJustifyAction); item.setMnemonic('C'); item = formatMenu.add(fullJustifyAction); item.setMnemonic('F'); menuBar.add(formatMenu); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); }
From source file:FramewithAboutMenu.java
public FramewithAboutMenu(String title) { JMenuBar menuBar = new JMenuBar(); setTitle(title);//from ww w. j a v a2 s . c o m setJMenuBar(menuBar); setDefaultCloseOperation(EXIT_ON_CLOSE); JMenu fileMenu = new JMenu("File"); JMenu elementMenu = new JMenu("Elements"); JMenu helpMenu = new JMenu("Help"); fileMenu.setMnemonic('F'); elementMenu.setMnemonic('E'); helpMenu.setMnemonic('H'); JMenuItem aboutItem = new JMenuItem("About"); helpMenu.add(aboutItem); menuBar.add(helpMenu); }
From source file:components.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 ava2 s.c om*/ //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; }