List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:AddingRemovingJMenu.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*w w w .j a va 2 s. co m*/ JMenu editMenu = new JMenu("Edit"); menuBar.add(editMenu); menuBar.remove(0); menuBar.revalidate(); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setAccelerator(KeyStroke.getKeyStroke("F")); // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New"); fileMenu.add(newMenuItem);/* ww w . ja v a 2 s .c o m*/ frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);// w w w .jav a2 s . c o m Action[] actions = ta.getActions(); JMenuBar menubar = new JMenuBar(); JMenu actionmenu = new JMenu("Actions"); menubar.add(actionmenu); JMenu firstHalf = new JMenu("1st Half"); JMenu secondHalf = new JMenu("2nd Half"); actionmenu.add(firstHalf); actionmenu.add(secondHalf); int mid = actions.length / 2; for (int i = 0; i < mid; i++) { firstHalf.add(actions[i]); } for (int i = mid; i < actions.length; i++) { secondHalf.add(actions[i]); } // Show it . . . JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(ta); f.setJMenuBar(menubar); f.setSize(300, 200); f.setVisible(true); }
From source file:MenuSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Menu Glue Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); bar.add(fileMenu);//from ww w . j a va2s . c o m // Edit Menu, E - Mnemonic JMenu editMenu = new JMenu("Edit"); editMenu.setMnemonic(KeyEvent.VK_E); bar.add(editMenu); // Move help menu to right side bar.add(Box.createHorizontalGlue()); // Help Menu, H - Mnemonic JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); bar.add(helpMenu); frame.setJMenuBar(bar); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JRadioButtonMenuItem Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Options"); menu.setMnemonic(KeyEvent.VK_O); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("A"); group.add(menuItem);//from w w w .j a v a2 s .c o m menu.add(menuItem); menuItem = new JRadioButtonMenuItem("B"); group.add(menuItem); menu.add(menuItem); menuItem = new JRadioButtonMenuItem("C"); group.add(menuItem); menu.add(menuItem); bar.add(menu); f.setJMenuBar(bar); f.setSize(300, 200); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);// www. j a va 2 s .c o m // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); // Separator fileMenu.addSeparator(); // File->Save, S - Mnemonic JMenuItem saveMenuItem = new JMenuItem("Save", KeyEvent.VK_S); fileMenu.add(saveMenuItem); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:SimpleToolbar.java
public static void main(String[] args) { JFrame f = new JFrame(); JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); menubar.add(file);//from w w w.j av a 2s.c o m f.setJMenuBar(menubar); JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("exit.png"); JButton exit = new JButton(icon); toolbar.add(exit); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); f.add(toolbar, BorderLayout.NORTH); f.setSize(300, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT); // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New"); fileMenu.add(newMenuItem);//from w w w. j a v a 2 s. co m frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JRadioButtonMenuItem Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); bar.addNotify();/*w ww . j a v a2s . c o m*/ JMenu menu = new JMenu("Options"); menu.setMnemonic(KeyEvent.VK_O); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("A"); group.add(menuItem); menu.add(menuItem); menuItem = new JRadioButtonMenuItem("B"); group.add(menuItem); menu.add(menuItem); menuItem = new JRadioButtonMenuItem("C"); group.add(menuItem); menu.add(menuItem); bar.add(menu); f.setJMenuBar(bar); f.setSize(300, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JRadioButtonMenuItem Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); bar.addNotify();/*w ww.ja v a 2 s.co m*/ JMenu menu = new JMenu("Options"); menu.setMnemonic(KeyEvent.VK_O); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("A"); group.add(menuItem); menu.add(menuItem); menuItem = new JRadioButtonMenuItem("B"); group.add(menuItem); menu.add(menuItem); menuItem = new JRadioButtonMenuItem("C"); group.add(menuItem); menu.add(menuItem); bar.add(menu); bar.removeNotify(); f.setJMenuBar(bar); f.setSize(300, 200); f.setVisible(true); }