List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:de.huberlin.cuneiform.compiler.debug.DebugDispatcher.java
private void addMenu() { JMenuBar menuBar;/*from www . j a v a 2 s. c om*/ JMenu fileMenu; JMenu helpMenu; JMenuItem aboutItem; menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); fileMenu = new JMenu("File"); menuBar.add(fileMenu); openItem = new JMenuItem("Open File ..."); fileMenu.add(openItem); exitItem = new JMenuItem("Exit"); exitItem.addActionListener(this); fileMenu.add(exitItem); helpMenu = new JMenu("Help"); menuBar.add(helpMenu); aboutItem = new JMenuItem("About Cuneiform"); helpMenu.add(aboutItem); }
From source file:TreeUtil.java
/** Creates the menus by using recursion */ public JMenuItem getMenus(DefaultMutableTreeNode node, JMenu parentMenu) { String name = node.getUserObject().toString(); int numChild = node.getChildCount(); if (numChild < 1) { JMenuItem tempMenu = new JMenuItem(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); return tempMenu; }//from w w w.j a v a2s. c o m JMenu tempMenu = new JMenu(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); for (int i = 0; i < numChild; i++) { tempMenu.add(getMenus((DefaultMutableTreeNode) node.getChildAt(i), tempMenu)); } return tempMenu; }
From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java
/** * Creates the menu bar.//from w w w. j a v a 2 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/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:ListCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. *///from www. jav a 2s . c om 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:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java
private JMenu buildCategoryMenu() { JMenu categoryMenu = new JMenu("Categories"); categoryMenu.setMnemonic('t'); JMenuItem showItem = new JMenuItem("Show"); showItem.setMnemonic('s'); JMenuItem addCatButton = createAddCatMenuItem(); showItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCategoriesNode()); }//from w ww.j a v a2 s .c o m }); categoryMenu.add(showItem); categoryMenu.addSeparator(); categoryMenu.add(addCatButton); return categoryMenu; }
From source file:net.chaosserver.timelord.swingui.TimelordMenu.java
/** * Creates the file menu.//from w w w.j a va 2 s . c o m * * @return the new file menu */ protected JMenu createFileMenu() { JMenu fileMenu = new JMenu(resourceBundle.getString(RROOT + ".fileMenuName")); JMenuItem menuItem; fileMenu.setMnemonic(KeyEvent.VK_F); JMenu exportMenu = new JMenu(resourceBundle.getString(RROOT + ".file.export")); exportMenu.setMnemonic(KeyEvent.VK_A); menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.jordan"), KeyEvent.VK_J); menuItem.setToolTipText(resourceBundle.getString(RROOT + ".file.export.jordan.tooltip")); menuItem.setActionCommand(ACTION_EXPORT_JORDAN); menuItem.addActionListener(this); exportMenu.add(menuItem); menuItem = new JMenuItem(resourceBundle.getString(RROOT + ".file.export.doug"), KeyEvent.VK_D); menuItem.setToolTipText("For Losers"); menuItem.setActionCommand(ACTION_EXPORT_DOUG); menuItem.addActionListener(this); exportMenu.add(menuItem); exportMenu.addSeparator(); menuItem = new JMenuItem("XML...", KeyEvent.VK_X); menuItem.setActionCommand(ACTION_EXPORT_XML); menuItem.addActionListener(this); exportMenu.add(menuItem); fileMenu.add(exportMenu); if (!OsUtil.isMac()) { fileMenu.addSeparator(); menuItem = new JMenuItem("Exit", KeyEvent.VK_X); menuItem.setActionCommand(ACTION_EXIT); menuItem.addActionListener(this); fileMenu.add(menuItem); } return fileMenu; }
From source file:au.org.ala.delta.editor.ui.image.ImageOverlayEditorController.java
public JPopupMenu buildPopupMenu() { disableActions();/*from w w w . j ava2 s. c om*/ boolean itemImage = (_selection.getSelectedImage().getSubject() instanceof Item); List<String> popupMenuActions = new ArrayList<String>(); if (_selection.getSelectedOverlay() != null) { popupMenuActions.add("editSelectedOverlay"); popupMenuActions.add("deleteSelectedOverlay"); popupMenuActions.add("-"); } popupMenuActions.add("deleteAllOverlays"); popupMenuActions.add("-"); popupMenuActions.add("displayImageSettings"); popupMenuActions.add("-"); popupMenuActions.add("cancelPopup"); JPopupMenu popup = new JPopupMenu(); MenuBuilder.buildMenu(popup, popupMenuActions, _actions); if (_selection.getSelectedOverlay() != null) { List<String> stackOverlayMenuActions = new ArrayList<String>(); stackOverlayMenuActions.add("stackSelectedOverlayHigher"); stackOverlayMenuActions.add("stackSelectedOverlayLower"); stackOverlayMenuActions.add("stackSelectedOverlayOnTop"); stackOverlayMenuActions.add("stackSelectedOverlayOnBottom"); JMenu stackOverlayMenu = new JMenu(_resources.getString("overlayPopup.stackOverlayMenu")); MenuBuilder.buildMenu(stackOverlayMenu, stackOverlayMenuActions, _actions); popup.add(stackOverlayMenu, 2); } List<String> insertOverlayMenuActions = new ArrayList<String>(); insertOverlayMenuActions.add("addTextOverlay"); if (itemImage) { insertOverlayMenuActions.add("addItemDescriptionOverlay"); } insertOverlayMenuActions.add("-"); if (!itemImage) { insertOverlayMenuActions.add("addAllUsualOverlays"); insertOverlayMenuActions.add("addFeatureDescriptionOverlay"); insertOverlayMenuActions.add("addStateOverlay"); insertOverlayMenuActions.add("addHotspot"); insertOverlayMenuActions.add("-"); } insertOverlayMenuActions.add("addOkOverlay"); insertOverlayMenuActions.add("addCancelOverlay"); if (!itemImage) { insertOverlayMenuActions.add("addNotesOverlay"); } else { insertOverlayMenuActions.add("addImageNotesOverlay"); } JMenu insertOverlayMenu = new JMenu(_resources.getString("overlayPopup.insertOverlayMenu")); MenuBuilder.buildMenu(insertOverlayMenu, insertOverlayMenuActions, _actions); int indexModifier = _selection.getSelectedOverlay() == null ? 4 : 0; popup.add(insertOverlayMenu, 5 - indexModifier); List<String> alignButtonsMenuActions = new ArrayList<String>(); alignButtonsMenuActions.add("useDefaultButtonAlignment"); alignButtonsMenuActions.add("*alignButtonsVertically"); alignButtonsMenuActions.add("*alignButtonsHorizontally"); alignButtonsMenuActions.add("*dontAlignButtons"); JMenu alignButtonsMenu = new JMenu(_resources.getString("overlayPopup.alignButtonsMenu")); alignButtonsMenu.setEnabled(getButtonOverlays().size() > 0); JMenuItem[] items = MenuBuilder.buildMenu(alignButtonsMenu, alignButtonsMenuActions, _actions); switch (_alignment) { case NO_ALIGN: items[3].setSelected(true); break; case ALIGN_HORIZONTALLY: items[2].setSelected(true); break; case ALIGN_VERTICALLY: items[1].setSelected(true); break; } popup.add(alignButtonsMenu, 7 - indexModifier); return popup; }
From source file:bio.gcat.gui.BDATool.java
public BDATool() { super("BDA Tool - " + AnalysisTool.NAME); setIconImage(getImage("bda")); setMinimumSize(new Dimension(660, 400)); setPreferredSize(new Dimension(1020, 400)); setSize(getPreferredSize());/*w ww. ja va2 s .c om*/ setLocationByPlatform(true); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); menubar = new JMenuBar(); menu = new JMenu[4]; menubar.add(menu[0] = new JMenu("File")); menubar.add(menu[1] = new JMenu("Edit")); menubar.add(menu[2] = new JMenu("Window")); menubar.add(menu[3] = new JMenu("Help")); setJMenuBar(menubar); menu[0].add(createMenuItem("Open...", "folder-horizontal-open", KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK), ACTION_OPEN, this)); menu[0].add(createMenuItem("Save As...", "disk--arrow", KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK), ACTION_SAVE_AS, this)); menu[0].add(createSeparator()); menu[0].add(createMenuItem("Close Window", "cross", ACTION_CLOSE, this)); menu[1].add(createMenuText("Binary Dichotomic Algorithm:")); menu[1].add(createMenuItem("Add", KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK), ACTION_BDA_ADD, this)); menu[1].add(createMenuItem("Edit...", KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_DOWN_MASK), ACTION_BDA_EDIT, this)); menu[1].add( createMenuItem("Remove", KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), ACTION_BDA_REMOVE, this)); menu[1].add(createMenuItem("Clear", ACTION_BDAS_CLEAR, this)); menu[1].add(seperateMenuItem(createMenuItem("Move Up", KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_DOWN_MASK), ACTION_BDA_MOVE_UP, this))); menu[1].add(createMenuItem("Move Down", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_DOWN_MASK), ACTION_BDA_MOVE_DOWN, this)); menu[2].add(createMenuItem("Preferences", ACTION_PREFERENCES, this)); menu[3].add(createMenuItem("About BDA Tool", "bda", ACTION_ABOUT, this)); for (String action : new String[] { ACTION_BDA_EDIT, ACTION_BDA_REMOVE, ACTION_BDAS_CLEAR, ACTION_BDA_MOVE_UP, ACTION_BDA_MOVE_DOWN }) getMenuItem(menubar, action).setEnabled(false); getMenuItem(menubar, ACTION_PREFERENCES).setEnabled(false); registerKeyStroke(getRootPane(), KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove", new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (bdaPanel.table.hasFocus()) removeBinaryDichotomicAlgorithm(); } }); toolbar = new JToolBar[1]; toolbar[0] = new JToolBar("File"); toolbar[0].add(createToolbarButton("Open File", "folder-horizontal-open", ACTION_OPEN, this)); toolbar[0].add(createToolbarButton("Save As File", "disk--arrow", ACTION_SAVE_AS, this)); toolbars = new JPanel(new FlowLayout(FlowLayout.LEADING)); for (JToolBar toolbar : toolbar) toolbars.add(toolbar); add(toolbars, BorderLayout.NORTH); add(createSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, true, 360, 0.195, new JScrollPane(bdaPanel = new BinaryDichotomicAlgorithmPanel()), new JScrollPane(tablePanel = new JPanel(new BorderLayout()))), BorderLayout.CENTER); add(bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)), BorderLayout.SOUTH); status = new JLabel(); status.setBorder(new EmptyBorder(0, 5, 0, 5)); status.setHorizontalAlignment(JLabel.RIGHT); bottom.add(status); ((ListTableModel<?>) bdaPanel.table.getModel()).addListDataListener(this); bdaPanel.table.getSelectionModel().addListSelectionListener(this); revalidateGeneticCodeTable(); }
From source file:DragPictureDemo2.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;// w w w . j av a 2s . c o m 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:common.AbstractGUI.java
private void createToolMenu() { toolMenu = new JMenu("Tools"); menuBar.add(toolMenu);// w ww . j a v a2 s . c om takeSnapshotMenuItem = new JMenuItem("Take snapshot"); takeSnapshotMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK)); takeSnapshotMenuItem.addActionListener(snapshotActionListener); toolMenu.add(takeSnapshotMenuItem); }