List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:edu.clemson.cs.nestbed.client.gui.NetworkMonitorFrame.java
private final JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem video = new JMenuItem("Video"); JMenuItem close = new JMenuItem("Close"); video.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { WebCam cam = new WebCam("nestbed.cs.clemson.edu", 9192); }//w w w . j a v a 2s .c o m }); menu.add(video); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { NetworkMonitorFrame.this.setVisible(false); } }); menu.add(new JSeparator()); menu.add(close); return menu; }
From source file:org.simbrain.plot.projection.ProjectionGui.java
/** * Creates the menu bar./* w ww . j a va2s . c o m*/ */ private void createAttachMenuBar() { final JMenuBar bar = new JMenuBar(); final JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); final JMenu exportImport = new JMenu("Export/Import..."); fileMenu.add(exportImport); exportImport.add(ProjectionPlotActions.getImportData(getWorkspaceComponent().getProjectionModel())); exportImport.addSeparator(); exportImport.add(ProjectionPlotActions.getExportDataHi(getWorkspaceComponent().getProjectionModel())); exportImport.add(ProjectionPlotActions.getExportDataLow(getWorkspaceComponent().getProjectionModel())); fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); final JMenu editMenu = new JMenu("Edit"); final JMenuItem preferencesGeneral = new JMenuItem("General Preferences..."); preferencesGeneral.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { ProjectionPreferencesDialog dialog = new ProjectionPreferencesDialog( getWorkspaceComponent().getProjectionModel().getProjector()); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } }); editMenu.add(preferencesGeneral); final JMenuItem colorPrefs = new JMenuItem("Datapoint Coloring..."); colorPrefs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DataPointColoringDialog dialog = new DataPointColoringDialog( getWorkspaceComponent().getProjectionModel()); dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } }); editMenu.add(colorPrefs); final JMenuItem dims = new JMenuItem("Set dimensions..."); dims.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String dimensions = JOptionPane.showInputDialog("Dimensions:"); if (dimensions != null) { getWorkspaceComponent().getProjectionModel().getProjector().init(Integer.parseInt(dimensions)); } } }); // editMenu.add(dims); JMenu helpMenu = new JMenu("Help"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:MenuActionExample.java
public MenuActionExample() { super(true);//from www . j a v a2 s .co m // Create a menu bar and give it a bevel border. menuBar = new JMenuBar(); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); // Create a menu and add it to the menu bar. JMenu menu = new JMenu("Menu"); menuBar.add(menu); // Create a toolbar and give it an etched border. toolBar = new JToolBar(); toolBar.setBorder(new EtchedBorder()); // Instantiate a sample action with the NAME property of // "Download" and the appropriate SMALL_ICON property. SampleAction exampleAction = new SampleAction("Download", new ImageIcon("action.gif")); // Finally, add the sample action to the menu and the toolbar. // These methods are no longer preferred: // menu.add(exampleAction); // toolBar.add(exampleAction); // Instead, you should create actual menu items and buttons: JMenuItem exampleItem = new JMenuItem(exampleAction); JButton exampleButton = new JButton(exampleAction); menu.add(exampleItem); toolBar.add(exampleButton); }
From source file:ListCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. *///from ww w . j a va 2 s. c o m public JMenuBar createMenuBar() { JMenuItem menuItem = null; JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); TransferActionListener actionListener = new TransferActionListener(); menuItem = new JMenuItem("Cut"); menuItem.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem("Copy"); menuItem.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem("Paste"); menuItem.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java
/** * Initialize the contents of the frame. *//*from w w w .j a v a2 s.c o m*/ private void initialize() { log.info("Plant Evaluator started"); frame = new JFrame(); frame.setIconImage(Icons.IC_APPLICATION_X_LARGE.getImage()); AppWindow._frame = frame; frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (reallyExit() == JOptionPane.YES_OPTION) { SingleInstance.release(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } }); frame.setTitle(Messages.getString("AppWindow.0") + " " + Messages.getString("AppWindow.version.code")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ frame.setLocationRelativeTo(null); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnFile = new JMenu(Messages.getString("AppWindow.1")); //$NON-NLS-1$ menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem(Messages.getString("AppWindow.3")); //$NON-NLS-1$ mntmExit.setIcon(Icons.IC_LOGOUT_SMALL); mntmExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { WindowEvent wev = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev); } }); mnFile.add(mntmExit); JMenu mnEdit = new JMenu(Messages.getString("AppWindow.4")); //$NON-NLS-1$ menuBar.add(mnEdit); JMenuItem mntmOptions = new JMenuItem(Messages.getString("AppWindow.5")); //$NON-NLS-1$ mntmOptions.setIcon(Icons.IC_PREFERENCES_SYSTEM_SMALL); mntmOptions.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new OptionsDialog(frame); } }); mnEdit.add(mntmOptions); JMenu mnTools = new JMenu(Messages.getString("AppWindow.mnTools.text")); //$NON-NLS-1$ menuBar.add(mnTools); JMenuItem mntmPostprocessing = new JMenuItem(Messages.getString("AppWindow.mntmPostprocessing.text")); //$NON-NLS-1$ mntmPostprocessing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } }); mnTools.add(mntmPostprocessing); JMenuItem mntmPlot = new JMenuItem(Messages.getString("AppWindow.mntmPlot.text")); //$NON-NLS-1$ mntmPlot.setIcon(Icons.IC_TOOL_PLOT_SMALL); mntmPlot.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { DialogUtil.getInstance().showPlotTypeSelection(); } }); mnTools.add(mntmPlot); JMenu mnHelp = new JMenu(Messages.getString("AppWindow.6")); //$NON-NLS-1$ menuBar.add(mnHelp); JMenuItem mntmAbout = new JMenuItem(Messages.getString("AppWindow.7")); //$NON-NLS-1$ mntmAbout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { new AboutDialog(frame); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mnHelp.add(mntmAbout); createContent(); DialogUtil.getInstance().setMainFrame(frame); }
From source file:org.jfree.chart.demo.JFreeChartDemo.java
/** * Creates a menubar.// w ww. j ava2 s .c o m * * @param resources localised resources. * * @return the menu bar. */ private JMenuBar createMenuBar(final ResourceBundle resources) { // create the menus final JMenuBar menuBar = new JMenuBar(); String label; Character mnemonic; // first the file menu label = resources.getString("menu.file"); mnemonic = (Character) resources.getObject("menu.file.mnemonic"); final JMenu fileMenu = new JMenu(label, true); fileMenu.setMnemonic(mnemonic.charValue()); label = resources.getString("menu.file.exit"); mnemonic = (Character) resources.getObject("menu.file.exit.mnemonic"); final JMenuItem exitItem = new JMenuItem(label, mnemonic.charValue()); exitItem.setActionCommand(EXIT_COMMAND); exitItem.addActionListener(this); fileMenu.add(exitItem); // then the help menu label = resources.getString("menu.help"); mnemonic = (Character) resources.getObject("menu.help.mnemonic"); final JMenu helpMenu = new JMenu(label); helpMenu.setMnemonic(mnemonic.charValue()); label = resources.getString("menu.help.about"); mnemonic = (Character) resources.getObject("menu.help.about.mnemonic"); final JMenuItem aboutItem = new JMenuItem(label, mnemonic.charValue()); aboutItem.setActionCommand(ABOUT_COMMAND); aboutItem.addActionListener(this); helpMenu.add(aboutItem); // finally, glue together the menu and return it menuBar.add(fileMenu); menuBar.add(helpMenu); return menuBar; }
From source file:StocksTable5.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu mFile = new JMenu("File"); mFile.setMnemonic('f'); JMenuItem mData = new JMenuItem("Retrieve Data..."); mData.setMnemonic('r'); ActionListener lstData = new ActionListener() { public void actionPerformed(ActionEvent e) { retrieveData();// w w w . j a va 2 s .c om } }; mData.addActionListener(lstData); mFile.add(mData); mFile.addSeparator(); JMenuItem mExit = new JMenuItem("Exit"); mExit.setMnemonic('x'); ActionListener lstExit = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; mExit.addActionListener(lstExit); mFile.add(mExit); menuBar.add(mFile); return menuBar; }
From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.corretor_eventos.PanelCorretorEventos.java
/** * Recria o menu editar do Frame Principal * //from w w w . jav a 2s .c o m * @param menu * @return */ private JMenu criaMenuEditar(JMenu menu) { menu.removeAll(); menu.setMnemonic('E'); menu.setMnemonic(KeyEvent.VK_E); menu.add(new JMenuItemTeclaAtalho(textAreaSourceCode)); menu.add(new JSeparator()); JMenuItem btnContraste = new JMenuItem(XHTML_Panel.ALTERAR_CONTRASTE); btnContraste.addActionListener(this); btnContraste.setActionCommand("Contraste"); // btnAumenta.setMnemonic('F'); // btnAumenta.setMnemonic(KeyEvent.VK_F); // btnAumenta.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, // ActionEvent.CTRL_MASK)); btnContraste.setToolTipText(XHTML_Panel.DICA_CONTRASTE); btnContraste.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_CONTRASTE); menu.add(btnContraste); JMenuItem btnAumenta = new JMenuItem(XHTML_Panel.AUMENTA_FONTE); btnAumenta.addActionListener(this); btnAumenta.setActionCommand("AumentaFonte"); // btnAumenta.setMnemonic('F'); // btnAumenta.setMnemonic(KeyEvent.VK_F); btnAumenta.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, ActionEvent.CTRL_MASK)); btnAumenta.setToolTipText(XHTML_Panel.DICA_AUMENTA_FONTE); btnAumenta.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_AUMENTA_FONTE); menu.add(btnAumenta); JMenuItem btnDiminui = new JMenuItem(XHTML_Panel.DIMINUI_FONTE); btnDiminui.addActionListener(this); btnDiminui.setActionCommand("DiminuiFonte"); // btnDiminui.setMnemonic('F'); // btnDiminui.setMnemonic(KeyEvent.VK_F); btnDiminui.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, ActionEvent.CTRL_MASK)); btnDiminui.setToolTipText(XHTML_Panel.DICA_DIMINUI_FONTE); btnDiminui.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_DIMINUI_FONTE); menu.add(btnDiminui); menu.add(new JSeparator()); JMenuItem btnProcurar = new JMenuItem(XHTML_Panel.PROCURAR); btnProcurar.addActionListener(this); btnProcurar.setActionCommand("Procurar"); btnProcurar.setMnemonic('P'); btnProcurar.setMnemonic(KeyEvent.VK_P); btnProcurar.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, ActionEvent.CTRL_MASK)); btnProcurar.setToolTipText(XHTML_Panel.DICA_PROCURAR); btnProcurar.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_PROCURAR); menu.add(btnProcurar); JMenuItem btnSelecionarTudo = new JMenuItem(XHTML_Panel.SELECIONAR_TUDO); btnSelecionarTudo.addActionListener(this); btnSelecionarTudo.setActionCommand("SelecionarTudo"); btnSelecionarTudo.setMnemonic('T'); btnSelecionarTudo.setMnemonic(KeyEvent.VK_T); btnSelecionarTudo.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, ActionEvent.CTRL_MASK)); btnSelecionarTudo.setToolTipText(XHTML_Panel.DICA_SELECIONAR_TUDO); btnSelecionarTudo.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_SELECIONAR_TUDO); menu.add(btnSelecionarTudo); JMenuItem btnDesfazer = new JMenuItem(XHTML_Panel.DESFAZER); btnDesfazer.addActionListener(this); btnDesfazer.setActionCommand("Desfazer"); btnDesfazer.setMnemonic('z'); btnDesfazer.setMnemonic(KeyEvent.VK_Z); btnDesfazer.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, ActionEvent.CTRL_MASK)); btnDesfazer.setToolTipText(XHTML_Panel.DICA_DESFAZER); btnDesfazer.getAccessibleContext().setAccessibleDescription(XHTML_Panel.DICA_DESFAZER); menu.add(btnDesfazer); return menu; }
From source file:ucar.unidata.idv.control.chart.ChartHolder.java
/** * Add in the zoom menu items/*from www . java 2s . c o m*/ * * @param items items */ private void addZoomMenuItems(List items) { JMenuItem mi; JMenu menu; items.add(menu = new JMenu("Zoom In")); menu.add(mi = new JMenuItem("All Axes")); mi.setActionCommand(ChartPanel.ZOOM_IN_BOTH_COMMAND); mi.addActionListener(chartPanel); menu.addSeparator(); menu.add(mi = new JMenuItem("Domain Axis")); mi.setActionCommand(ChartPanel.ZOOM_IN_DOMAIN_COMMAND); mi.addActionListener(chartPanel); menu.add(mi = new JMenuItem("Range Axis")); mi.setActionCommand(ChartPanel.ZOOM_IN_RANGE_COMMAND); mi.addActionListener(chartPanel); items.add(menu = new JMenu("Zoom Out")); menu.add(mi = new JMenuItem("All Axes")); mi.setActionCommand(ChartPanel.ZOOM_OUT_BOTH_COMMAND); mi.addActionListener(chartPanel); menu.addSeparator(); menu.add(mi = new JMenuItem("Domain Axis")); mi.setActionCommand(ChartPanel.ZOOM_OUT_DOMAIN_COMMAND); mi.addActionListener(chartPanel); menu.add(mi = new JMenuItem("Range Axis")); mi.setActionCommand(ChartPanel.ZOOM_OUT_RANGE_COMMAND); mi.addActionListener(chartPanel); items.add(menu = new JMenu("Auto Range")); menu.add(mi = new JMenuItem("All Axes")); mi.setActionCommand(ChartPanel.ZOOM_RESET_BOTH_COMMAND); mi.addActionListener(chartPanel); menu.addSeparator(); menu.add(mi = new JMenuItem("Domain Axis")); mi.setActionCommand(ChartPanel.ZOOM_RESET_DOMAIN_COMMAND); mi.addActionListener(chartPanel); menu.add(mi = new JMenuItem("Range Axis")); mi.setActionCommand(ChartPanel.ZOOM_RESET_RANGE_COMMAND); mi.addActionListener(chartPanel); }
From source file:ca.phon.app.session.editor.view.segmentation.SegmentationEditorView.java
@Override public JMenu getMenu() { final JMenu retVal = new JMenu(); final KeyStroke noPartKs = KeyStroke.getKeyStroke(KeyEvent.VK_0, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); final NewSegmentAction noSpeakerAct = new NewSegmentAction(getEditor(), this, null); noSpeakerAct.putValue(NewSegmentAction.NAME, "New record with unspecified speaker"); noSpeakerAct.putValue(NewSegmentAction.ACCELERATOR_KEY, noPartKs); retVal.add(noSpeakerAct); final Session session = getEditor().getSession(); int pIdx = 1; for (Participant p : session.getParticipants()) { final KeyStroke partKs = KeyStroke.getKeyStroke(KeyEvent.VK_0 + (pIdx++), Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); final NewSegmentAction speakerAct = new NewSegmentAction(getEditor(), this, p); speakerAct.putValue(NewSegmentAction.NAME, "New record for " + p.toString()); speakerAct.putValue(NewSegmentAction.ACCELERATOR_KEY, partKs); retVal.add(speakerAct);// w w w . j ava 2 s .c o m } return retVal; }