List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:JToggleButtonMenuItem.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 JToggleButtonMenuItem newMenuItem = new JToggleButtonMenuItem("New"); fileMenu.add(newMenuItem); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:Main.java
public static JMenu menu(String name, JMenuItem... items) { final JMenu menu = new JMenu(name); for (JMenuItem item : items) { if (item != null) { menu.add(item);/*from w ww.ja va 2s. c om*/ } else { menu.addSeparator(); } } return menu; }
From source file:com.google.code.facebook.graph.sna.applet.GraphEditorDemo.java
/** * a driver for this demo/*from w ww . j a va2 s . co m*/ */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:Main.java
static public JMenu createJMenu(JMenuBar pMenuBar, String pMenuText, char pMnemonic) { final JMenu menu = new JMenu(pMenuText); menu.setMnemonic(pMnemonic);// ww w .jav a 2 s .co m if (defaultFont != null) menu.setFont(defaultFont); pMenuBar.add(menu); return menu; }
From source file:Main.java
/** * Convenience method for creating a JMenu * @param text the menu title/*from www.ja va2s . co 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:external.jung.demo.GraphEditorDemo.java
/** * a driver for this demo/*from ww w . ja v a 2 s.c o m*/ */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:Main.java
/** * Creates a sub-menu for changing Look'n'Feel. * @param rootComponent the root component which Look'n'Feel should be changed (child component are processed recursively). * @return a menu item with sub-menu items for each Look'n'Feel * installed in the system with associated actions to change the * Look'n'Feel for the <code>rootComponent</root>. *//*from www .ja v a 2s .c o m*/ public static JMenu getLafMenu(final Component rootComponent) { JMenu jMenu = new JMenu("Look & Feel"); ButtonGroup buttonGroup = new ButtonGroup(); final UIManager.LookAndFeelInfo[] installedLFs = UIManager.getInstalledLookAndFeels(); String currentLF = UIManager.getLookAndFeel().getName(); for (int i = 0; i < installedLFs.length; i++) { JCheckBoxMenuItem jMenuItem = new JCheckBoxMenuItem(installedLFs[i].getName()); jMenu.add(jMenuItem); buttonGroup.add(jMenuItem); jMenuItem.setState(currentLF.equals(installedLFs[i].getName())); class ChangeLF extends AbstractAction { private UIManager.LookAndFeelInfo iLF; public ChangeLF(UIManager.LookAndFeelInfo iLF) { super(iLF.getName()); this.iLF = iLF; } public void actionPerformed(ActionEvent e) { try { UIManager.setLookAndFeel(iLF.getClassName()); SwingUtilities.updateComponentTreeUI(rootComponent); } catch (Exception ex) { System.out.print("Could not set look and feel: " + ex.toString()); } } } jMenuItem.setAction(new ChangeLF(installedLFs[i])); } return jMenu; }
From source file:GraphEditorDemo.java
/** * a driver for this demo//from ww w . j a v a 2s . c om */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); menu.add(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeTopologyFile(file); } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu);//from w ww . java2s . c om menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit"), 0); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); bar.add(menu);/*w ww . j a v a 2s . co m*/ menu.add(new JMenuItem("Close")); menu.add(new JSeparator()); // SEPARATOR menu.add(new JMenuItem("Exit")); setJMenuBar(bar); add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }