List of usage examples for javax.swing JMenu addSeparator
public void addSeparator()
From source file:MainClass.java
public MainClass() { super();//from w w w .ja v a2s .c o m setChannel(currentNumber); numberLabel.setHorizontalAlignment(JLabel.CENTER); numberLabel.setFont(new Font("Serif", Font.PLAIN, 32)); getContentPane().add(numberLabel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16)); getContentPane().add(buttonPanel, BorderLayout.CENTER); buttonPanel.add(new JButton(upAction)); buttonPanel.add(new JButton(gotoFavoriteAction)); buttonPanel.add(new JButton(downAction)); buttonPanel.add(new JButton(setFavoriteAction)); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("Number"); menu.add(new JMenuItem(upAction)); menu.add(new JMenuItem(downAction)); menu.addSeparator(); menu.add(new JMenuItem(gotoFavoriteAction)); menu.add(new JMenuItem(setFavoriteAction)); mb.add(menu); setJMenuBar(mb); }
From source file:MenuTest.java
public MenuTest() { super();/*from w ww. j av a2s. c o m*/ MenuListener listener = new MenuListener() { public void menuCanceled(MenuEvent e) { dumpInfo("Canceled", e); } public void menuDeselected(MenuEvent e) { dumpInfo("Deselected", e); } public void menuSelected(MenuEvent e) { dumpInfo("Selected", e); } private void dumpInfo(String s, MenuEvent e) { JMenu menu = (JMenu) e.getSource(); System.out.println(s + ": " + menu.getText()); } }; JMenu fileMenu = new JMenu("File"); fileMenu.addMenuListener(listener); fileMenu.add(new JMenuItem("Open")); fileMenu.add(new JMenuItem("Close")); fileMenu.add(new JMenuItem("Exit")); JMenu helpMenu = new JMenu("Help"); helpMenu.addMenuListener(listener); helpMenu.add(new JMenuItem("About MenuTest")); helpMenu.add(new JMenuItem("Class Hierarchy")); helpMenu.addSeparator(); helpMenu.add(new JCheckBoxMenuItem("Balloon Help")); JMenu subMenu = new JMenu("Categories"); subMenu.addMenuListener(listener); JRadioButtonMenuItem rb; ButtonGroup group = new ButtonGroup(); subMenu.add(rb = new JRadioButtonMenuItem("A Little Help", true)); group.add(rb); subMenu.add(rb = new JRadioButtonMenuItem("A Lot of Help")); group.add(rb); helpMenu.add(subMenu); JMenuBar mb = new JMenuBar(); mb.add(fileMenu); mb.add(helpMenu); setJMenuBar(mb); }
From source file:ActionExampleSwing.java
public ActionExampleSwing() { super("ActionExample Swing"); setChannel(currentChannel); // enable/disable the Actions as appropriate channelLabel.setHorizontalAlignment(JLabel.CENTER); channelLabel.setFont(new Font("Serif", Font.PLAIN, 32)); getContentPane().add(channelLabel, BorderLayout.NORTH); JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16)); getContentPane().add(buttonPanel, BorderLayout.CENTER); buttonPanel.add(new JButton(upAction)); buttonPanel.add(new JButton(gotoFavoriteAction)); buttonPanel.add(new JButton(downAction)); buttonPanel.add(new JButton(setFavoriteAction)); JMenuBar mb = new JMenuBar(); JMenu menu = new JMenu("Channel"); menu.add(new JMenuItem(upAction)); menu.add(new JMenuItem(downAction)); menu.addSeparator(); menu.add(new JMenuItem(gotoFavoriteAction)); menu.add(new JMenuItem(setFavoriteAction)); mb.add(menu);/*from www . j av a2 s . co m*/ setJMenuBar(mb); }
From source file:org.pgptool.gui.ui.keyslist.KeysListView.java
private void initMenuBar() { menuBar = new JMenuBar(); JMenu menuTs = new JMenu(Messages.get("term.actions")); menuTs.add(miImport = new JMenuItem()); menuTs.add(miCreate = new JMenuItem()); menuTs.addSeparator(); menuTs.add(miExportPublicKeys = new JMenuItem()); menuTs.addSeparator();//from w w w . j a v a2s. com menuTs.add(miClose = new JMenuItem()); menuBar.add(menuTs); }
From source file:commonline.query.gui.Frame.java
private void initializeMenu(boolean isMac) { JMenu file = new JMenu("File"); JMenuItem open = new JMenuItem(openAction); JMenuItem clear = new JMenuItem(clearDatabaseAction); JMenuItem exit = new JMenuItem(new ExitAction()); file.add(open);/*from w w w . j av a 2 s.c o m*/ file.addSeparator(); file.add(clear); if (!isMac) { file.addSeparator(); file.add(exit); } JMenu query = new JMenu("Query"); JMenuItem execute = new JMenuItem(executeScriptAction); JMenuItem stop = new JMenuItem(stopScriptAction); query.add(execute); query.add(stop); JMenuBar menuBar = new JMenuBar(); menuBar.add(file); menuBar.add(query); setJMenuBar(menuBar); }
From source file:org.simbrain.plot.piechart.PieChartGui.java
/** * Creates the menu bar./*from w w w . j av a2 s .c o m*/ */ private void createAttachMenuBar() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); JMenu editMenu = new JMenu("Edit"); JMenuItem preferences = new JMenuItem("Preferences..."); preferences.addActionListener(this); preferences.setActionCommand("dialog"); editMenu.add(preferences); JMenu helpMenu = new JMenu("Help"); ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/pie_chart.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:org.simbrain.plot.barchart.BarChartGui.java
/** * Creates the menu bar.//www . java 2 s. c om */ private void createAttachMenuBar() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); JMenu editMenu = new JMenu("Edit"); JMenuItem preferences = new JMenuItem("Preferences..."); preferences.addActionListener(this); preferences.setActionCommand("dialog"); editMenu.add(preferences); JMenu helpMenu = new JMenu("Help"); ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/bar_chart.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java
/** * Creates the menu bar./*from w ww .j a v a 2s.c om*/ */ private void createAttachMenuBar() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); JMenu editMenu = new JMenu("Edit"); JMenuItem preferences = new JMenuItem("Preferences..."); preferences.addActionListener(this); preferences.setActionCommand("dialog"); editMenu.add(preferences); JMenu helpMenu = new JMenu("Help"); ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/scatter_plot.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:Main.java
Main() { JFrame f = new JFrame("Menu Demo"); f.setSize(220, 200);/*www . j a v a 2 s .c o m*/ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar jmb = new JMenuBar(); JMenu jmFile = new JMenu("File"); JMenuItem jmiOpen = new JMenuItem("Open"); JMenuItem jmiClose = new JMenuItem("Close"); JMenuItem jmiSave = new JMenuItem("Save"); JMenuItem jmiExit = new JMenuItem("Exit"); jmFile.add(jmiOpen); jmFile.add(jmiClose); jmFile.add(jmiSave); jmFile.addSeparator(); jmFile.add(jmiExit); jmb.add(jmFile); JMenu jmOptions = new JMenu("Options"); JMenu a = new JMenu("A"); JMenuItem b = new JMenuItem("B"); JMenuItem c = new JMenuItem("C"); JMenuItem d = new JMenuItem("D"); a.add(b); a.add(c); a.add(d); jmOptions.add(a); JMenu e = new JMenu("E"); e.add(new JMenuItem("F")); e.add(new JMenuItem("G")); jmOptions.add(e); jmb.add(jmOptions); JMenu jmHelp = new JMenu("Help"); JMenuItem jmiAbout = new JMenuItem("About"); jmHelp.add(jmiAbout); jmb.add(jmHelp); jmiOpen.addActionListener(this); jmiClose.addActionListener(this); jmiSave.addActionListener(this); jmiExit.addActionListener(this); b.addActionListener(this); c.addActionListener(this); d.addActionListener(this); jmiAbout.addActionListener(this); f.setJMenuBar(jmb); f.setVisible(true); }
From source file:MainClass.java
public MainClass() { setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/*from ww w . j av a 2 s .co 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); }