List of usage examples for javax.swing JFrame setJMenuBar
@BeanProperty(bound = false, hidden = true, description = "The menubar for accessing pulldown menus from this frame.") public void setJMenuBar(final JMenuBar menubar)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);/*from ww w .j a v a 2 s .c o m*/ JMenuItem menuItem = new JMenuItem("Print"); KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK); menuItem.setAccelerator(ctrlP); menuItem.addActionListener(printAction); menu.add(menuItem); JButton fileButton = new JButton("About"); fileButton.setMnemonic(KeyEvent.VK_A); fileButton.addActionListener(printAction); frame.setJMenuBar(menuBar); frame.add(fileButton, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:UseActions.java
public static void main(String args[]) { JFrame frame = new JFrame("Use TextAction"); Container contentPane = frame.getContentPane(); Dimension empty = new Dimension(0, 0); final JTextArea leftArea = new JTextArea(); JScrollPane leftScrollPane = new JScrollPane(leftArea); leftScrollPane.setPreferredSize(empty); final JTextArea rightArea = new JTextArea(); JScrollPane rightScrollPane = new JScrollPane(rightArea); rightScrollPane.setPreferredSize(empty); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu menu = new JMenu("Options"); menuBar.add(menu);/* www.j a v a 2 s . c o m*/ JMenuItem menuItem; Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction); menuItem = menu.add(readAction); menuItem.setText("Make read-only"); Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction); menuItem = menu.add(writeAction); menuItem.setText("Make writable"); menu.addSeparator(); Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction); menuItem = menu.add(cutAction); menuItem.setText("Cut"); Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction); menuItem = menu.add(copyAction); menuItem.setText("Copy"); Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction); menuItem = menu.add(pasteAction); menuItem.setText("Paste"); contentPane.add(splitPane, BorderLayout.CENTER); frame.setSize(400, 250); frame.setVisible(true); splitPane.setDividerLocation(.5); }
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);/*from w ww. j a v a 2 s .co m*/ // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive", true); caseMenuItem.setMnemonic(KeyEvent.VK_C); fileMenu.add(caseMenuItem); System.out.println(caseMenuItem.getSelectedObjects().length); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.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);/*w ww . j a v a 2 s. c om*/ // 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:ScreenDump.java
public static void main(String args[]) { JFrame frame = new JFrame("Action Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Action printAction = new PrintHelloAction(); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu);/*from w w w. java 2s . c om*/ JMenuItem menuItem = new JMenuItem("Print"); KeyStroke ctrlP = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK); menuItem.setAccelerator(ctrlP); menuItem.addActionListener(printAction); menu.add(menuItem); JButton fileButton = new JButton("About"); fileButton.setMnemonic(KeyEvent.VK_A); fileButton.addActionListener(printAction); frame.setJMenuBar(menuBar); Container contentPane = frame.getContentPane(); contentPane.add(fileButton, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:livecanvas.mesheditor.MeshEditor.java
public static void main(String[] args) throws Exception { // AlloyLookAndFeel.setProperty("alloy.licenseCode", // "2011/06/29#asidjoaisdjoasidjid@mailinator.com#lj8xv#1a193l"); // AlloyLookAndFeel.setProperty("alloy.isToolbarEffectsEnabled", // "false");/*from w w w . ja v a 2 s .co m*/ // try { // AlloyLookAndFeel alloyLnF = new AlloyLookAndFeel(); // alloyLnF.setTheme(new GlassTheme(), true); // UIManager.setLookAndFeel(alloyLnF); // } catch (UnsupportedLookAndFeelException ex) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // } JFrame f = new JFrame("LiveCanvas - Mesh Editor"); final MeshEditor meshEditor = new MeshEditor(); f.setJMenuBar(meshEditor.getMenuBar()); f.getContentPane().add(meshEditor); f.getContentPane().add(meshEditor.getToolBar(), BorderLayout.NORTH); f.pack(); f.setLocationRelativeTo(null); f.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); // meshEditor.exit(); } }); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); f.setVisible(true); // meshEditor.open(new File("C:/Users/Jasleen/Desktop/prez.mesh")); }
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();/*from w ww . ja v a 2s . 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); bar.removeNotify(); 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();// ww w . ja v a 2 s.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); bar.setHelpMenu(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();/*from w ww . ja v a 2s . 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); bar.setSelected(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();//from w ww . j a v a2 s . 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); JMenu m = bar.getMenu(0); f.setJMenuBar(bar); f.setSize(300, 200); f.setVisible(true); }