Example usage for javax.swing JMenuItem JMenuItem

List of usage examples for javax.swing JMenuItem JMenuItem

Introduction

In this page you can find the example usage for javax.swing JMenuItem JMenuItem.

Prototype

public JMenuItem(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the specified Action.

Usage

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();//  w ww . ja v a 2s  . c om
        }
    });
    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:de.dakror.virtualhub.server.ServerFrame.java

public void init() {
    initFiles();//from  w  w  w  .ja  v  a2  s  . co 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: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  w  w  .  ja  v  a 2  s .co  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:dbseer.gui.panel.DBSeerExplainChartPanel.java

public DBSeerExplainChartPanel(JFreeChart chart, JTextArea log, DBSeerExplainControlPanel controlPanel) {
    super(chart);
    normalRegion = new ArrayList<Double>();
    anomalyRegion = new ArrayList<Double>();
    this.setLayout(new MigLayout("fill"));
    this.setMouseWheelEnabled(true);
    this.explainConsole = log;
    this.controlPanel = controlPanel;
    this.popupMenu = this.getPopupMenu();

    JMenuItem popupItem;// www  .  j  a  v  a2 s  .co  m
    //      popupItem = new JMenuItem(new ExplainChartAction("Select as Anomaly (Marked as Black)", DBSeerConstants.EXPLAIN_SELECT_ANOMALY_REGION,
    //            this));
    //      popupMenu.add(popupItem);
    //      popupItem = new JMenuItem(new ExplainChartAction("Select as Normal (Marked as White, Optional)", DBSeerConstants.EXPLAIN_SELECT_NORMAL_REGION,
    //            this));
    //      popupMenu.add(popupItem);
    popupMenu.insert(new JSeparator(), 0);
    popupItem = new JMenuItem(new ExplainChartAction("Clear All", DBSeerConstants.EXPLAIN_CLEAR_REGION, this));
    popupMenu.insert(popupItem, 0);
    popupItem = new JMenuItem(new ExplainChartAction("Select as Normal (Optional)",
            DBSeerConstants.EXPLAIN_APPEND_NORMAL_REGION, this));
    popupMenu.insert(popupItem, 0);
    popupItem = new JMenuItem(
            new ExplainChartAction("Select as Anomaly", DBSeerConstants.EXPLAIN_APPEND_ANOMALY_REGION, this));
    popupMenu.insert(popupItem, 0);
    //      popupMenu.add(popupItem);
    //      popupMenu.add(popupItem);
    //
    //      popupMenu.add(popupItem);
    //      popupMenu.addSeparator();
    //      popupItem = new JMenuItem(new ExplainChartAction("Explain", DBSeerConstants.EXPLAIN_EXPLAIN, this));
    //      popupMenu.add(popupItem);
    //      popupMenu.addSeparator();
    //      showPredicatesMenuItem = new JMenuItem(new ExplainChartAction("Show Predicates", DBSeerConstants.EXPLAIN_SHOW_PREDICATES, this));
    //      showPredicatesMenuItem.setEnabled(false);
    //      popupMenu.add(showPredicatesMenuItem);
    //      savePredicatesMenuItem = new JMenuItem(new ExplainChartAction("Save Predicates as Causal Model", DBSeerConstants.EXPLAIN_SAVE_PREDICATES, this));
    //      savePredicatesMenuItem.setEnabled(false);
    //      popupMenu.add(savePredicatesMenuItem);

    super.setPopupMenu(this.popupMenu);
}

From source file:gdt.jgui.tool.JTextEditor.java

/**
 * Get context menu.//from w w  w .j a  v a 2  s .  c  om
 * @return the 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) {
            //System.out.println("TextEditor:done:text="+editorPane.getText());
            if (requesterResponseLocator$ != null) {
                try {
                    byte[] ba = Base64.decodeBase64(requesterResponseLocator$);
                    String responseLocator$ = new String(ba, "UTF-8");
                    text$ = editorPane.getText();
                    if (base64)
                        text$ = Locator.compressText(text$);
                    responseLocator$ = Locator.append(responseLocator$, TEXT, text$);
                    System.out.println("TextEditor:done:response locator="
                            + Locator.remove(responseLocator$, Locator.LOCATOR_ICON));
                    JConsoleHandler.execute(console, responseLocator$);
                } catch (Exception ee) {
                    LOGGER.severe(ee.toString());
                }
            } else {
                //System.out.println("TextEditor:done:requester locator is null");
                console.back();
            }
        }
    });
    menu.add(doneItem);
    JMenuItem cancelItem = new JMenuItem("Cancel");
    cancelItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            console.back();
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem encryptItem = new JMenuItem("Encrypt/Decrypt");
    encryptItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JTextEncrypter ten = new JTextEncrypter();
            String tenLocator$ = ten.getLocator();
            tenLocator$ = Locator.append(tenLocator$, Entigrator.ENTIHOME, entihome$);
            tenLocator$ = Locator.append(tenLocator$, JTextEditor.TEXT, editorPane.getText());
            String tedLocator$ = getLocator();
            tedLocator$ = Locator.append(tedLocator$, BaseHandler.HANDLER_METHOD, "response");
            tedLocator$ = Locator.append(tedLocator$, JRequester.REQUESTER_ACTION, ACTION_ENCODE_TEXT);
            tenLocator$ = Locator.append(tenLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR,
                    Locator.compressText(tedLocator$));
            JConsoleHandler.execute(console, tenLocator$);
        }
    });
    menu.add(encryptItem);
    return menu;
}

From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java

private void createMenuBarItem(JMenuBar menuBar, MenuItem item) {
    String caption = menuConfig.getItemCaption(item.getId());
    if (!item.getChildren().isEmpty() || item.isMenu()) {
        final JMenu jMenu = new JMenu(caption);
        jMenu.addMenuListener(new MenuListener() {
            @Override/*from ww  w.ja  va  2s  . c o  m*/
            public void menuSelected(MenuEvent e) {
                jMenu.requestFocus();
            }

            @Override
            public void menuDeselected(MenuEvent e) {
            }

            @Override
            public void menuCanceled(MenuEvent e) {
            }
        });
        jMenu.setName(item.getId());
        menuBar.add(jMenu);
        createSubMenu(jMenu, item);
    } else {
        JMenuItem jMenuItem = new JMenuItem(caption);
        jMenuItem.setName(item.getId());
        //todo remove hardcoded border
        jMenuItem.setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 4));
        assignShortcut(jMenuItem, item);
        jMenuItem.setMaximumSize(
                new Dimension(jMenuItem.getPreferredSize().width, jMenuItem.getMaximumSize().height));
        assignCommand(jMenuItem, item);
        menuBar.add(jMenuItem);
    }
}

From source file:org.esa.beam.visat.toolviews.stat.MaskSelectionToolSupport.java

public JMenuItem createDeleteMaskMenuItem() {
    final JMenuItem menuItem = new JMenuItem(String.format("Delete Mask '%s' ", maskName));
    menuItem.setName("deleteMask");
    menuItem.addActionListener(new ActionListener() {
        @Override//from  w w  w .j  a  v a  2s. c  o  m
        public void actionPerformed(ActionEvent e) {
            if (plotAreaSelectionTool != null) {
                plotAreaSelectionTool.removeAnnotation();
            }
            Product product = pagePanel.getProduct();
            if (product != null) {
                Mask mask = product.getMaskGroup().get(maskName);
                if (mask != null) {
                    product.getMaskGroup().remove(mask);
                }
            }
        }
    });
    return menuItem;
}

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);/*from w ww . ja v a 2  s  .  com*/

    // 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:XMLWriteTest.java

public XMLWriteFrame() {
    setTitle("XMLWriteTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    chooser = new JFileChooser();

    // add component to frame

    comp = new RectangleComponent();
    add(comp);//from w  ww  .ja v  a2  s  .  c  o  m

    // set up menu bar

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem newItem = new JMenuItem("New");
    menu.add(newItem);
    newItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            comp.newDrawing();
        }
    });

    JMenuItem saveItem = new JMenuItem("Save with DOM/XSLT");
    menu.add(saveItem);
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveDocument();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

    JMenuItem saveStAXItem = new JMenuItem("Save with StAX");
    menu.add(saveStAXItem);
    saveStAXItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                saveStAX();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(XMLWriteFrame.this, e.toString());
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:cz.lidinsky.editor.Menu.java

/**
 *  Adds new menu item at the end of the menu.
 */// www.ja  v  a 2s . co m
Menu addItem(String text, String actionCommand, ActionListener listener) {
    JMenuItem item = new JMenuItem(text);
    item.setActionCommand(actionCommand);
    item.addActionListener(listener);
    JMenu lastMenu = getMenu(getMenuCount() - 1);
    lastMenu.add(item);
    return this;
}