List of usage examples for javax.swing JMenu addSeparator
public void addSeparator()
From source file:Main.java
public Main() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);//from www . j a v a 2 s.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:de.tbuchloh.kiskis.gui.MainFramePanel.java
protected static void addActions(final JMenu fileMenu, final Action[] actions) { for (int i = 0; i < actions.length; ++i) { if (actions[i] == null) { fileMenu.addSeparator(); } else {// w w w . j a va 2 s . co m fileMenu.add(actions[i]); } } }
From source file:edu.ku.brc.specify.config.init.SpecifyDBSetupWizardFrame.java
/** * @return// ww w.j a v a 2 s. c o m */ public JMenuBar createMenus() { JMenuBar mb = new JMenuBar(); JMenuItem mi; //-------------------------------------------------------------------- //-- File Menu //-------------------------------------------------------------------- if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { JMenu menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ menu.addSeparator(); String title = "Specify.EXIT"; //$NON-NLS-1$ String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doExit(true); } }); } helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ HelpMgr.createHelpMenuItem(helpMenu, "Specify"); //$NON-NLS-1$ helpMenu.addSeparator(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { String ttle = "Specify.ABOUT";//$NON-NLS-1$ String mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ String desc = "Specify.ABOUT";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doAbout(); } }); } return mb; }
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 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:MenuTest.java
public MenuFrame() { setTitle("MenuTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); fileMenu.add(new TestAction("New")); // demonstrate accelerators JMenuItem openItem = fileMenu.add(new TestAction("Open")); openItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O")); fileMenu.addSeparator(); saveAction = new TestAction("Save"); JMenuItem saveItem = fileMenu.add(saveAction); saveItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S")); saveAsAction = new TestAction("Save As"); fileMenu.add(saveAsAction);/*from w ww . java 2 s .com*/ fileMenu.addSeparator(); fileMenu.add(new AbstractAction("Exit") { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // demonstrate check box and radio button menus readonlyItem = new JCheckBoxMenuItem("Read-only"); readonlyItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { boolean saveOk = !readonlyItem.isSelected(); saveAction.setEnabled(saveOk); saveAsAction.setEnabled(saveOk); } }); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem insertItem = new JRadioButtonMenuItem("Insert"); insertItem.setSelected(true); JRadioButtonMenuItem overtypeItem = new JRadioButtonMenuItem("Overtype"); group.add(insertItem); group.add(overtypeItem); // demonstrate icons Action cutAction = new TestAction("Cut"); cutAction.putValue(Action.SMALL_ICON, new ImageIcon("cut.gif")); Action copyAction = new TestAction("Copy"); copyAction.putValue(Action.SMALL_ICON, new ImageIcon("copy.gif")); Action pasteAction = new TestAction("Paste"); pasteAction.putValue(Action.SMALL_ICON, new ImageIcon("paste.gif")); JMenu editMenu = new JMenu("Edit"); editMenu.add(cutAction); editMenu.add(copyAction); editMenu.add(pasteAction); // demonstrate nested menus JMenu optionMenu = new JMenu("Options"); optionMenu.add(readonlyItem); optionMenu.addSeparator(); optionMenu.add(insertItem); optionMenu.add(overtypeItem); editMenu.addSeparator(); editMenu.add(optionMenu); // demonstrate mnemonics JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('H'); JMenuItem indexItem = new JMenuItem("Index"); indexItem.setMnemonic('I'); helpMenu.add(indexItem); // you can also add the mnemonic key to an action Action aboutAction = new TestAction("About"); aboutAction.putValue(Action.MNEMONIC_KEY, new Integer('A')); helpMenu.add(aboutAction); // add all top-level menus to menu bar JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); // demonstrate pop-ups popup = new JPopupMenu(); popup.add(cutAction); popup.add(copyAction); popup.add(pasteAction); JPanel panel = new JPanel(); panel.setComponentPopupMenu(popup); add(panel); // the following line is a workaround for bug 4966109 panel.addMouseListener(new MouseAdapter() { }); }
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);// w w w . ja va2 s . c om 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:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
public DisplayAAS() { dbAuswahlAAS = JKabelS.getSpringContext().getBean(DBAuswahlAAS.class); setTitle("jKabel"); getContentPane().setLayout(new BorderLayout()); getContentPane().add(south = getSouth(), BorderLayout.SOUTH); //File menue//from www . j a va2 s. c o m JMenu menue = new JMenu("File"); menue.add(edit); menue.add(search); menue.add(auchf); menue.addSeparator(); menue.add(getjTypSortMenu()); menue.add(getjTrommelSortMenu()); menue.addSeparator(); menue.add(exit); edit.addActionListener(this); search.addActionListener(this); exit.addActionListener(this); auchf.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setZeigeAlle(auchf.isSelected()); } catch (IOException e) { e.printStackTrace(); } } }); //License and more JMenu lMenue = new JMenu("Hilfe"); lMenue.add(help); lMenue.add(gpl); help.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new HelpAAS(); } }); gpl.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new GPLAAS(); } }); // und zusammenbauen menuBar.add(menue); menuBar.add(lMenue); menuBar.add(new Version()); // Trommelsuchband JMenuItem sbt = new JMenuItem("Suchen nach Trommelnummer"); menuBar.add(sbt); sbt.addActionListener(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class)); JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class).setVisible(false); getContentPane().add(JKabelS.getSpringContext().getBean(SearchTrommelNrAAS.class), BorderLayout.NORTH); setJMenuBar(menuBar); IDBWrapper db = dbAuswahlAAS.getDBWrapper(); bearbeitenPanel = (JPanel) JKabelS.getSpringContext().getBean("bearbeitenPanel"); if (db == null) { center.add(new JLabel("Es konnte keine Verbindung zur DB hergestellt werden.")); center.add(new JLabel( "Wenn !!!sicher!!! ist das kein anderer auf der DB arbeitet die lock.lck Datei lschen")); DisplayAAS d = this; getContentPane().add(center, BorderLayout.CENTER); } else { setDb(db); } setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setVisible(true); }
From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizardFrame.java
/** * @return//from ww w . j a va2 s . c o m */ public JMenuBar createMenus() { JMenuBar mb = new JMenuBar(); JMenuItem mi; //-------------------------------------------------------------------- //-- File Menu //-------------------------------------------------------------------- if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { JMenu menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ menu.addSeparator(); String title = "Specify.EXIT"; //$NON-NLS-1$ String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doExit(true); } }); } JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ HelpMgr.createHelpMenuItem(helpMenu, "Specify"); //$NON-NLS-1$ helpMenu.addSeparator(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { String ttle = "Specify.ABOUT";//$NON-NLS-1$ String mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ String desc = "Specify.ABOUT";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doAbout(); } }); } return mb; }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the File... Menu./* w w w. j a v a 2s .c om*/ * * @return the File Menu */ protected JMenu fileMenu() { JMenu jme = new JMenu(KstatResources.getString("FILE.TEXT")); jme.setMnemonic(KeyEvent.VK_F); saveItem = new JMenuItem(KstatResources.getString("FILE.SAVEAS.TEXT"), KeyEvent.VK_S); saveItem.addActionListener(this); jme.add(saveItem); jme.addSeparator(); exitItem = new JMenuItem(KstatResources.getString("FILE.CLOSE.TEXT"), KeyEvent.VK_C); exitItem.addActionListener(this); jme.add(exitItem); return jme; }
From source file:net.sf.housekeeper.swing.MainFrame.java
/** * Builds the menus./*from w w w. j a va 2 s. co m*/ * * @return The created menu bar. Is not null. */ private JMenuBar buildMenuBar() { final JMenuBar menuBar = new JMenuBar(); //File Menu final String fileMenuLabel = LocalisationManager.INSTANCE.getText("gui.menu.file"); final JMenu menuFile = new JMenu(fileMenuLabel); menuBar.add(menuFile); menuFile.add(new JMenuItem(new LoadDataAction())); menuFile.add(new JMenuItem(new SaveDataAction())); menuFile.addSeparator(); menuFile.add(new JMenuItem(new ExitAction())); //Help Menu final String helpMenuString = LocalisationManager.INSTANCE.getText("gui.menu.help"); final JMenu menuHelp = new JMenu(helpMenuString); menuBar.add(Box.createHorizontalGlue()); menuBar.add(menuHelp); menuHelp.add(new JMenuItem(new AboutDialogAction())); return menuBar; }