List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:external.jung.demo.RoadEditorDemo.java
/** * a driver for this demo/*from w w w.j av a 2s . c om*/ */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final RoadEditorDemo demo = new RoadEditorDemo(); JMenu menu = new JMenu("File"); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); frame.pack(); frame.setVisible(true); }
From source file:components.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);/* w ww. j a v a 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:gdt.jgui.base.JPropertyPanel.java
/** * Get context menu. //from w w w . j a va 2 s . co m * @return context menu.. */ @Override public JMenu getContextMenu() { JMenu menu = new JMenu("Context"); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu.add(doneItem); return menu; }
From source file:MessageDigestTest.java
public MessageDigestFrame() { setTitle("MessageDigestTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel panel = new JPanel(); ButtonGroup group = new ButtonGroup(); addRadioButton(panel, "SHA-1", group); addRadioButton(panel, "MD5", group); add(panel, BorderLayout.NORTH); add(new JScrollPane(message), BorderLayout.CENTER); add(digest, BorderLayout.SOUTH); digest.setFont(new Font("Monospaced", Font.PLAIN, 12)); setAlgorithm("SHA-1"); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem fileDigestItem = new JMenuItem("File digest"); fileDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadFile();// www. j a va2 s . c o m } }); menu.add(fileDigestItem); JMenuItem textDigestItem = new JMenuItem("Text area digest"); textDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String m = message.getText(); computeDigest(m.getBytes()); } }); menu.add(textDigestItem); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java
private JMenu newExportMenu() { DemetraUI demetraUI = DemetraUI.getDefault(); JMenu result = new JMenu("Export image to"); result.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_FLOPPY_O)); JMenuItem copy = new ActionMenuItem(ChartCommand.copyImage().toAction(chartPanel)); copy.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_CLIPBOARD)); copy.setText("Clipboard"); JMenuItem file = new ActionMenuItem(ChartCommand.saveImage().toAction(chartPanel)); file.setIcon(demetraUI.getPopupMenuIcon(FontAwesome.FA_PICTURE_O)); file.setText("File..."); result.add(copy);/*from w ww . j a va 2 s. c om*/ result.add(file); return result; }
From source file:com.github.pemapmodder.pocketminegui.gui.server.ServerMainActivity.java
@Override protected void onStart() { lifetime = new ServerLifetime(this); // setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); setLayout(new GridBagLayout()); JMenuBar bar = new JMenuBar(); JMenu serverMenu = new JMenu("Server"); serverMenu.setMnemonic(KeyEvent.VK_S); JMenu playerMenu = new JMenu("Players"); playerMenu.setMnemonic(KeyEvent.VK_P); bar.add(serverMenu);/*from w ww . j av a 2 s .com*/ bar.add(playerMenu); setJMenuBar(bar); startStopButton = new JButton("Start"); startStopButton.addActionListener(lifetime::listen); GridBagConstraints constr = new GridBagConstraints(); constr.gridx = 0; constr.gridy = 0; constr.fill = GridBagConstraints.VERTICAL; constr.weighty = 0.02; constr.weightx = 0.1; add(startStopButton, constr); constr.gridx = 1; constr.gridy = 1; constr.fill = GridBagConstraints.BOTH; constr.weightx = 0.8; constr.weighty = 0.9; add(consolePanel = new ConsolePanel(this), constr); }
From source file:components.MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;//from w w w . j a v a 2 s. com JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }
From source file:MenuShortcuts.java
MenuShortcuts(String s) { super("JMenuShortcuts: " + s); mb = new JMenuBar(); setJMenuBar(mb); // Frame implements JMenuContainer Container cp = getContentPane(); JMenuItem mi;/*from w w w .ja va2 s . c om*/ // The File JMenu... fm = new JMenu("File"); fm.setMnemonic('F'); fm.add(mi = new JMenuItem("Open", 'O')); mi.addActionListener(this); fm.add(mi = new JMenuItem("Close", 'W')); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new JMenuItem("Print", 'P')); mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.ALT_MASK)); mi.addActionListener(this); fm.addSeparator(); fm.add(mi = new JMenuItem("Exit", 'Q')); exitItem = mi; // save for action handler mi.addActionListener(this); mb.add(fm); // The Options JMenu... om = new JMenu("Options"); om.add(new JMenuItem("Alpha")); om.add(new JMenuItem("Gamma")); om.add(new JMenuItem("Delta")); mb.add(om); // The Help JMenu... hm = new JMenu("Help"); hm.add(mi = new JMenuItem("About")); mi.addActionListener(this); hm.add(mi = new JMenuItem("Topics")); mi.addActionListener(this); mb.add(hm); // mb.setHelpMenu(hm); // needed for portability (Motif, etc.). // the main window cp.add(new Label("Menu Demo Window", 200, 150)); pack(); }
From source file:de.dakror.virtualhub.server.ServerFrame.java
public void init() { initFiles();/*from w w w . jav a 2 s. c o m*/ logArea = new JTextArea(); logArea.setWrapStyleWord(true); logArea.setEditable(false); logArea.setLineWrap(true); DefaultCaret caret = (DefaultCaret) logArea.getCaret(); caret.setSelectionVisible(false); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); wrap = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); setContentPane(wrap); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Aktionen"); menu.add(new JMenuItem( new AbstractAction("Protokoll leeren", new ImageIcon(getClass().getResource("/img/trash.png"))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { logArea.setText(""); log("Protokoll geleert."); } })); menu.add(logEnabled = new JCheckBoxMenuItem("Protokoll aktiviert", new ImageIcon(getClass().getResource("/img/log.png")), true)); menu.add(packetLogEnabled = new JCheckBoxMenuItem("Paketverkehr protokollieren", new ImageIcon(getClass().getResource("/img/traffic.png")), false)); menu.addSeparator(); menu.add(new JMenuItem(new AbstractAction("Backup-Einstellungen", new ImageIcon(getClass().getResource("/img/backup_edit.png"))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { try { BackupEditDialog.show(); } catch (JSONException e1) { e1.printStackTrace(); } } })); menuBar.add(menu); setJMenuBar(menuBar); }
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. *//*w w w . j ava 2s .c o m*/ @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); }