List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:OptPaneComparison.java
public OptPaneComparison(final String message) { setDefaultCloseOperation(EXIT_ON_CLOSE); final int msgType = JOptionPane.QUESTION_MESSAGE; final int optType = JOptionPane.OK_CANCEL_OPTION; final String title = message; setSize(350, 200);//from w w w .j a v a 2s. co m // Create a desktop for internal frames final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); // Add a simple menu bar JMenuBar mb = new JMenuBar(); setJMenuBar(mb); JMenu menu = new JMenu("Dialog"); JMenu imenu = new JMenu("Internal"); mb.add(menu); mb.add(imenu); final JMenuItem construct = new JMenuItem("Constructor"); final JMenuItem stat = new JMenuItem("Static Method"); final JMenuItem iconstruct = new JMenuItem("Constructor"); final JMenuItem istat = new JMenuItem("Static Method"); menu.add(construct); menu.add(stat); imenu.add(iconstruct); imenu.add(istat); // Create our JOptionPane. We're asking for input, so we call // setWantsInput. // Note that we cannot specify this via constructor parameters. optPane = new JOptionPane(message, msgType, optType); optPane.setWantsInput(true); // Add a listener for each menu item that will display the appropriate // dialog/internal frame construct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JDialog d = optPane.createDialog(desk, title); d.setVisible(true); respond(getOptionPaneValue()); } }); stat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInputDialog(desk, message, title, msgType); respond(s); } }); iconstruct.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { // Create and display the dialog JInternalFrame f = optPane.createInternalFrame(desk, title); f.setVisible(true); // Listen for the frame to close before getting the value from // it. f.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if ((ev.getPropertyName().equals(JInternalFrame.IS_CLOSED_PROPERTY)) && (ev.getNewValue() == Boolean.TRUE)) { respond(getOptionPaneValue()); } } }); } }); istat.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { String s = JOptionPane.showInternalInputDialog(desk, message, title, msgType); respond(s); } }); }
From source file:be.fedict.eid.tsl.tool.TslTool.java
private void initNewMenu(JMenu fileMenu) { JMenu newMenu = new JMenu("New"); newMenu.setMnemonic(KeyEvent.VK_N); fileMenu.add(newMenu); JMenu belgiumMenu = new JMenu("Belgium"); newMenu.add(belgiumMenu);/* w w w . j a v a2 s .co m*/ JMenu _2010BelgiumMenu = new JMenu("2010"); belgiumMenu.add(_2010BelgiumMenu); JMenuItem _2010_T1_BelgiumMenuItem = addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2010-T1", _2010BelgiumMenu, true); _2010BelgiumMenu.add(_2010_T1_BelgiumMenuItem); JMenuItem _2010_T2_BelgiumMenuItem = addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2010-T2", _2010BelgiumMenu, true); _2010BelgiumMenu.add(_2010_T2_BelgiumMenuItem); JMenuItem _2010_T3_BelgiumMenuItem = addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2010-T3", _2010BelgiumMenu, true); _2010BelgiumMenu.add(_2010_T3_BelgiumMenuItem); JMenu _2011BelgiumMenu = new JMenu("2011"); belgiumMenu.add(_2011BelgiumMenu); addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2011-T1", _2011BelgiumMenu, true); addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2011-T2", _2011BelgiumMenu, true); addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2011-T3", _2011BelgiumMenu, true); JMenu _2012BelgiumMenu = new JMenu("2012"); belgiumMenu.add(_2012BelgiumMenu); addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2012-T1", _2012BelgiumMenu, true); addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2012-T2", _2012BelgiumMenu, true); addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2012-T3", _2012BelgiumMenu, true); JMenu _2013BelgiumMenu = new JMenu("2013"); belgiumMenu.add(_2013BelgiumMenu); addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2013-T1", _2013BelgiumMenu, true); addActionMenuItem("Trimester 2", KeyEvent.VK_2, "TSL-BE-2013-T2", _2013BelgiumMenu, true); addActionMenuItem("Trimester 3", KeyEvent.VK_3, "TSL-BE-2013-T3", _2013BelgiumMenu, true); JMenu _2014BelgiumMenu = new JMenu("2014"); belgiumMenu.add(_2014BelgiumMenu); addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2014-T1", _2014BelgiumMenu, true); addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2014-T2", _2014BelgiumMenu, true); addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2014-T3", _2014BelgiumMenu, true); JMenu _2015BelgiumMenu = new JMenu("2015"); belgiumMenu.add(_2015BelgiumMenu); addActionMenuItem("Trimester 1", KeyEvent.VK_1, "TSL-BE-2015-T1", _2015BelgiumMenu, true); addActionMenuItem("Trimester 2", KeyEvent.VK_1, "TSL-BE-2015-T2", _2015BelgiumMenu, true); addActionMenuItem("Trimester 3", KeyEvent.VK_1, "TSL-BE-2015-T3", _2015BelgiumMenu, true); }
From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java
private void buildMenuBar() { menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menu.setMnemonic('F'); menu.add(fileOpenScriptsAction); menu.add(fileEditPropertiesAction);// w w w.java2 s. c o m menu.addSeparator(); menu.add(fileExitAction); menuBar.add(menu); menu = new JMenu("Tools"); menu.setMnemonic('T'); menu.add(toolsRunAction); menuBar.add(menu); }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
/** * Receives notification when a Series has been edited or the Series list has changed. * * @param event information about the event. *///from w w w . j av a 2s . c om @Override public void datasetChanged(DatasetChangeEvent event) { menu.removeAll(); for (Series s : series.toArray(new Series[series.size()])) { this.menus.put(s, createPopupMenuForSeries(s)); JMenu jMenu = new JMenu(s.getName()); for (Component item : createPopupMenuForSeries(s).getComponents()) { if (item instanceof JMenuItem || item instanceof JSeparator) { jMenu.add(item); } } menu.add(jMenu); } menu.setVisible(menu.getMenuComponentCount() > 0); }
From source file:InternalFrameDemo.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); // Set up the lone menu. JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu);/* www .j a va 2 s . c o m*/ // Set up the first menu item. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); // Set up the second menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; }
From source file:XPathTest.java
public XPathFrame() { setTitle("XPathTest"); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();/*from w ww. j a v a 2 s . com*/ } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { evaluate(); } }; expression = new JTextField(20); expression.addActionListener(listener); JButton evaluateButton = new JButton("Evaluate"); evaluateButton.addActionListener(listener); typeCombo = new JComboBox(new Object[] { "STRING", "NODE", "NODESET", "NUMBER", "BOOLEAN" }); typeCombo.setSelectedItem("STRING"); JPanel panel = new JPanel(); panel.add(expression); panel.add(typeCombo); panel.add(evaluateButton); docText = new JTextArea(10, 40); result = new JTextField(); result.setBorder(new TitledBorder("Result")); add(panel, BorderLayout.NORTH); add(new JScrollPane(docText), BorderLayout.CENTER); add(result, BorderLayout.SOUTH); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { JOptionPane.showMessageDialog(this, e); } XPathFactory xpfactory = XPathFactory.newInstance(); path = xpfactory.newXPath(); pack(); }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the Statistics Menu, showing all available statistics for the * chosen ChartableKstat.//from w w w .j a v a2s . c o m * * @param cks the Kstat to show the statistics of in the menu * @param statistic the initial statistic, which will be checked * * @return the Statistics Menu */ protected JMenu statisticsMenu(ChartableKstat cks, String statistic) { JMenu jmstat = new JMenu(KstatResources.getString("CHART.SHOW")); jmstat.setMnemonic(KeyEvent.VK_S); for (String stat : cks.getStatistics()) { JCheckBoxMenuItem jmi = new JCheckBoxMenuItem(stat, stat.equals(statistic)); jmi.addActionListener(this); jmstat.add(jmi); } return jmstat; }
From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the Statistics Menu, showing all available statistics for the * chosen ChartableKstat./*from ww w.j a v a 2 s .c om*/ * * @param cks the ChartableKstat to show the statistics of in the menu * @param statistics the initial statistics, which will be checked * * @return the Statistics Menu */ protected JMenu statisticsMenu(ChartableKstat cks, List<String> statistics) { JMenu jmstat = new JMenu(KstatResources.getString("CHART.SHOW")); jmstat.setMnemonic(KeyEvent.VK_S); for (String stat : cks.getStatistics()) { JCheckBoxMenuItem jmi = new JCheckBoxMenuItem(stat, statistics.contains(stat)); jmi.addActionListener(this); jmstat.add(jmi); } return jmstat; }
From source file:com.haskins.cloudtrailviewer.sidebar.EventsStats.java
private void addSourceMenu() { JRadioButtonMenuItem mnuEventName = new JRadioButtonMenuItem("Event Name"); JRadioButtonMenuItem mnuAwsRegion = new JRadioButtonMenuItem("AWS Region"); JRadioButtonMenuItem mnuSourceIpAddress = new JRadioButtonMenuItem("Source IP Address"); JRadioButtonMenuItem mnuUserAgent = new JRadioButtonMenuItem("User Agent"); JRadioButtonMenuItem mnuEventSource = new JRadioButtonMenuItem("Event Source"); JRadioButtonMenuItem mnuErrorCode = new JRadioButtonMenuItem("Error Code"); JRadioButtonMenuItem mnuRecipientAccountId = new JRadioButtonMenuItem("Recipient Account Id"); mnuEventName.setActionCommand("EventName"); mnuEventName.addActionListener(this); mnuEventName.setSelected(true);/*from ww w .j a va2s . c o m*/ mnuAwsRegion.setActionCommand("AwsRegion"); mnuAwsRegion.addActionListener(this); mnuSourceIpAddress.setActionCommand("SourceIPAddress"); mnuSourceIpAddress.addActionListener(this); mnuUserAgent.setActionCommand("UserAgent"); mnuUserAgent.addActionListener(this); mnuEventSource.setActionCommand("EventSource"); mnuEventSource.addActionListener(this); mnuErrorCode.setActionCommand("ErrorCode"); mnuErrorCode.addActionListener(this); mnuRecipientAccountId.setActionCommand("RecipientAccountId"); mnuRecipientAccountId.addActionListener(this); sourceGroup.add(mnuEventName); sourceGroup.add(mnuAwsRegion); sourceGroup.add(mnuSourceIpAddress); sourceGroup.add(mnuUserAgent); sourceGroup.add(mnuEventSource); sourceGroup.add(mnuErrorCode); sourceGroup.add(mnuRecipientAccountId); JMenu sourceMenu = new JMenu("Source"); sourceMenu.add(mnuEventName); sourceMenu.add(mnuAwsRegion); sourceMenu.add(mnuSourceIpAddress); sourceMenu.add(mnuUserAgent); sourceMenu.add(mnuEventSource); sourceMenu.add(mnuErrorCode); sourceMenu.add(mnuRecipientAccountId); sourceMenu.add(getUserIdentityMenu(sourceGroup)); menu.add(sourceMenu); }
From source file:misc.TextBatchPrintingDemo.java
/** * Create and display the main application frame. */// www .j a v a 2s .co m void createAndShowGUI() { messageArea = new JLabel(defaultMessage); selectedPages = new JList(new DefaultListModel()); selectedPages.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); selectedPages.addListSelectionListener(this); setPage(homePage); JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(pageItem), new JScrollPane(selectedPages)); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); /** Menu item and keyboard shortcuts for the "add page" command. */ fileMenu.add(createMenuItem(new AbstractAction("Add Page") { public void actionPerformed(ActionEvent e) { DefaultListModel pages = (DefaultListModel) selectedPages.getModel(); pages.addElement(pageItem); selectedPages.setSelectedIndex(pages.getSize() - 1); } }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "print selected" command.*/ fileMenu.add(createMenuItem(new AbstractAction("Print Selected") { public void actionPerformed(ActionEvent e) { printSelectedPages(); } }, KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "clear selected" command.*/ fileMenu.add(createMenuItem(new AbstractAction("Clear Selected") { public void actionPerformed(ActionEvent e) { DefaultListModel pages = (DefaultListModel) selectedPages.getModel(); pages.removeAllElements(); } }, KeyEvent.VK_C, KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK))); fileMenu.addSeparator(); /** Menu item and keyboard shortcuts for the "home page" command. */ fileMenu.add(createMenuItem(new AbstractAction("Home Page") { public void actionPerformed(ActionEvent e) { setPage(homePage); } }, KeyEvent.VK_H, KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.ALT_MASK))); /** Menu item and keyboard shortcuts for the "quit" command. */ fileMenu.add(createMenuItem(new AbstractAction("Quit") { public void actionPerformed(ActionEvent e) { for (Window w : Window.getWindows()) { w.dispose(); } } }, KeyEvent.VK_A, KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK))); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(pane); contentPane.add(messageArea); JFrame frame = new JFrame("Text Batch Printing Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menuBar); frame.setContentPane(contentPane); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); if (printService == null) { // Actual printing is not possible, issue a warning message. JOptionPane.showMessageDialog(frame, "No default print service", "Print Service Alert", JOptionPane.WARNING_MESSAGE); } }