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:DataExchangeTest.java

public DataExchangeFrame() {
    setTitle("DataExchangeTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // construct a File menu

    JMenuBar mbar = new JMenuBar();
    setJMenuBar(mbar);// ww  w.j  a va 2s. c o m
    JMenu fileMenu = new JMenu("File");
    mbar.add(fileMenu);

    // add Connect and Exit menu items

    JMenuItem connectItem = new JMenuItem("Connect");
    connectItem.addActionListener(new ConnectAction());
    fileMenu.add(connectItem);

    // The Exit item exits the program

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

    textArea = new JTextArea();
    add(new JScrollPane(textArea), BorderLayout.CENTER);
}

From source file:com.db2eshop.gui.menu.RightClickPopupMenu.java

/**
 * <p>Constructor for RightClickPopupMenu.</p>
 *///from ww  w.  j av a2s.  c om
public RightClickPopupMenu() {
    show = new JMenuItem("Show Entity");
    add = new JMenuItem("Add Entity");
    edit = new JMenuItem("Edit Entity");
    remove = new JMenuItem("Remove Entity");

    this.add(show);
    this.add(new JSeparator());
    this.add(add);
    this.add(edit);
    this.add(remove);

    this.pack();
}

From source file:grafix.telas.componentes.GrafixChartMouseListener.java

private void criarPopupMenu() {
    popup = new JPopupMenu();
    JMenuItem menuItem;//from   ww  w .ja va2 s  . c om

    menuItem = new JMenuItem("Configurar janela...");
    menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "config.gif"));
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            abrirFormConfiguracoes(-1);
        }
    });
    popup.add(menuItem);

    menuItem = new JMenuItem("Configurar grfico...");
    menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "configurar3.gif"));
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            abrirFormConfiguracoes(plotClicado);
        }
    });
    popup.add(menuItem);

    menuItem = new JMenuItem("ndices...");
    menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "indices.gif"));
    menuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            abrirFormIndices(plotClicado);
        }
    });
    popup.add(menuItem);
}

From source file:ProgressMonitorInputStreamTest.java

public TextFrame() {
    setTitle("ProgressMonitorInputStreamTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    textArea = new JTextArea();
    add(new JScrollPane(textArea));

    chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*from   w w w  .j  av a  2  s.c o m*/
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    openItem = new JMenuItem("Open");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                openFile();
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
    });

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

From source file:Java2DExample.java

public JMenuItem createMenuItem(String menuItemName, char mnemonic, final MyFilter filter) {
    JMenuItem menuItem = new JMenuItem(menuItemName);
    menuItem.setMnemonic(mnemonic);/*from w  w  w .  j a v a2  s  .c o m*/
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent action) {
            imagePanel.applyFilter(filter);
        }

    });
    return menuItem;
}

From source file:commonline.query.gui.Frame.java

private void initializeMenu(boolean isMac) {
    JMenu file = new JMenu("File");
    JMenuItem open = new JMenuItem(openAction);
    JMenuItem clear = new JMenuItem(clearDatabaseAction);
    JMenuItem exit = new JMenuItem(new ExitAction());

    file.add(open);/*from w w  w  .  j  av a  2 s.  co m*/
    file.addSeparator();
    file.add(clear);
    if (!isMac) {
        file.addSeparator();
        file.add(exit);
    }

    JMenu query = new JMenu("Query");
    JMenuItem execute = new JMenuItem(executeScriptAction);
    JMenuItem stop = new JMenuItem(stopScriptAction);

    query.add(execute);
    query.add(stop);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(file);
    menuBar.add(query);
    setJMenuBar(menuBar);
}

From source file:InternalFrameTest.java

public DesktopFrame() {
    setTitle("InternalFrameTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    desktop = new JDesktopPane();
    add(desktop, BorderLayout.CENTER);

    // set up menus

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);//from  w ww  .  j  a v a2s.  c o  m
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    JMenuItem openItem = new JMenuItem("New");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            createInternalFrame(new JLabel(new ImageIcon(planets[counter] + ".gif")), planets[counter]);
            counter = (counter + 1) % planets.length;
        }
    });
    fileMenu.add(openItem);
    JMenuItem exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
    fileMenu.add(exitItem);
    JMenu windowMenu = new JMenu("Window");
    menuBar.add(windowMenu);
    JMenuItem nextItem = new JMenuItem("Next");
    nextItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            selectNextWindow();
        }
    });
    windowMenu.add(nextItem);
    JMenuItem cascadeItem = new JMenuItem("Cascade");
    cascadeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            cascadeWindows();
        }
    });
    windowMenu.add(cascadeItem);
    JMenuItem tileItem = new JMenuItem("Tile");
    tileItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            tileWindows();
        }
    });
    windowMenu.add(tileItem);
    final JCheckBoxMenuItem dragOutlineItem = new JCheckBoxMenuItem("Drag Outline");
    dragOutlineItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            desktop.setDragMode(dragOutlineItem.isSelected() ? JDesktopPane.OUTLINE_DRAG_MODE
                    : JDesktopPane.LIVE_DRAG_MODE);
        }
    });
    windowMenu.add(dragOutlineItem);
}

From source file:MenuDemo1.java

public static JMenuItem menuItem(String label, ActionListener listener, String command, int mnemonic,
        int acceleratorKey) {
    JMenuItem item = new JMenuItem(label);
    item.addActionListener(listener);/*from ww  w .  ja  v a 2  s  .co  m*/
    item.setActionCommand(command);
    if (mnemonic != 0)
        item.setMnemonic((char) mnemonic);
    if (acceleratorKey != 0)
        item.setAccelerator(KeyStroke.getKeyStroke(acceleratorKey, java.awt.Event.CTRL_MASK));
    return item;
}

From source file:ImageIOTest.java

public ImageIOFrame() {
    setTitle("ImageIOTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    JMenu fileMenu = new JMenu("File");
    JMenuItem openItem = new JMenuItem("Open");
    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            openFile();//from   w w w  .  ja v a  2s  .c  o m
        }
    });
    fileMenu.add(openItem);

    JMenu saveMenu = new JMenu("Save");
    fileMenu.add(saveMenu);
    Iterator<String> iter = writerFormats.iterator();
    while (iter.hasNext()) {
        final String formatName = iter.next();
        JMenuItem formatItem = new JMenuItem(formatName);
        saveMenu.add(formatItem);
        formatItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                saveFile(formatName);
            }
        });
    }

    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);
}

From source file:com.egangotri.transliteratorAsSwing.TransliteratorJFrame.java

public TransliteratorJFrame() {
    super("eGangotri Indic Transliterator");

    PrintWriter pw = new PrintWriter(System.out, true);
    setSize(650, 650);//from   w w w.j a va2 s.  c  o  m

    // menubar
    menubar = new JMenuBar();

    // menus
    file = new JMenu("File");
    help = new JMenu("Help");

    // JMenuItem
    save_1 = new JMenuItem("Save Input");
    save_1.setActionCommand("save_1");
    save_1.addActionListener(this);

    save_2 = new JMenuItem("Save Output-1");
    save_2.setActionCommand("save_2");
    save_2.addActionListener(this);

    save_3 = new JMenuItem("Save Output-2");
    save_3.setActionCommand("save_3");
    save_3.addActionListener(this);

    open_1 = new JMenuItem("Open File for Input");
    open_1.setActionCommand("open_1");
    open_1.addActionListener(this);

    exitItem = new JMenuItem("Exit");
    exitItem.setActionCommand("Exit");
    exitItem.addActionListener(this);

    aboutItem = new JMenuItem("About");
    aboutItem.setActionCommand("about_item");
    aboutItem.addActionListener(this);

    itransItem = new JMenuItem("ITRANS " + Constants.ENCODING_SCHEME);
    itransItem.setActionCommand("itrans_encoding");
    itransItem.addActionListener(this);

    slpItem = new JMenuItem("SLP " + Constants.ENCODING_SCHEME);
    slpItem.setActionCommand("slp_encoding");
    slpItem.addActionListener(this);

    hkItem = new JMenuItem("Harvard Kyoto " + Constants.ENCODING_SCHEME);
    hkItem.setActionCommand("hk_encoding");
    hkItem.addActionListener(this);

    velthuisItem = new JMenuItem("Velthuis " + Constants.ENCODING_SCHEME);
    velthuisItem.setActionCommand("velthuis_encoding");
    velthuisItem.addActionListener(this);

    dvnItem = new JMenuItem("Devanagari " + Constants.ENCODING_SCHEME);
    dvnItem.setActionCommand("devanagari_encoding");
    dvnItem.addActionListener(this);

    iastItem = new JMenuItem("IAST " + Constants.ENCODING_SCHEME);
    iastItem.setActionCommand("iast_encoding");
    iastItem.addActionListener(this);

    // add menuitems to menu
    file.add(open_1);
    file.add(save_1);
    file.add(save_2);
    file.add(save_3);
    file.add(exitItem);

    help.add(aboutItem);
    help.add(itransItem);
    help.add(slpItem);
    help.add(hkItem);
    help.add(velthuisItem);
    help.add(dvnItem);
    help.add(iastItem);

    // add menus to menubar
    menubar.add(file);
    menubar.add(help);
    // menus end

    // JPanel Initilization
    p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p1a = new JPanel(new BorderLayout());
    p2 = new JPanel();
    p3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p3a = new JPanel(new BorderLayout());

    p4 = new JPanel();
    p5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    p5a = new JPanel(new BorderLayout());

    p6 = new JPanel();
    p6a = new JPanel();
    p7 = new JPanel();

    // JLabel Initialization
    label1 = new JLabel("Input:");
    label2 = new JLabel("Output-1");
    label3 = new JLabel("Output-2");

    capitalize = new JCheckBox("Capitalize Extended Latin");
    capitalize.setSelected(capitalizeIAST);
    capitalize.setActionCommand("capitalize");
    capitalize.addActionListener(this);

    // Buttons
    clearButton = new JButton("Clear");
    clearButton.setActionCommand("clear");
    clearButton.setToolTipText("Clear all Fields");

    refreshButton = new JButton("Refresh");
    refreshButton.setActionCommand("refresh");
    refreshButton.setToolTipText("Refesh the View");

    exitButton = new JButton("Exit");
    exitButton.setActionCommand("Exit");
    exitButton.setToolTipText("Quit the Application.");

    clipboardButton1 = new JButton("Clipboard");
    clipboardButton1.setActionCommand("clipboard-1");
    clipboardButton1.setToolTipText("Clipboard Input");

    clipboardButton2 = new JButton("Clipboard");
    clipboardButton2.setActionCommand("clipboard-2");
    clipboardButton2.setToolTipText("Clipboard Output-1");

    clipboardButton3 = new JButton("Clipboard");
    clipboardButton3.setActionCommand("clipboard-3");
    clipboardButton3.setToolTipText("Clipboard Output-2");

    clearButton.addActionListener(this);
    refreshButton.addActionListener(this);
    exitButton.addActionListener(this);

    clipboardButton1.addActionListener(this);
    clipboardButton2.addActionListener(this);
    clipboardButton3.addActionListener(this);

    Container contentPane = getContentPane();

    // JTextBox
    tb1 = new JTextArea(new PlainDocument(), null, 6, 45);
    tb1.setLineWrap(true);
    tb1.setWrapStyleWord(true);
    tb1.addKeyListener(this);

    tb2 = new JTextArea(new PlainDocument(), null, 6, 45);
    tb2.setLineWrap(true);
    tb2.setWrapStyleWord(true);
    tb2.addKeyListener(this);

    tb3 = new JTextArea(new PlainDocument(), null, 6, 45);
    tb3.setLineWrap(true);
    tb3.setWrapStyleWord(true);
    tb3.addKeyListener(this);

    // Setting Fonts
    Font unicodeFont = new Font(Constants.ARIAL_UNICODE_MS, Font.PLAIN, Constants.FONT_SIZE);
    tb1.setFont(unicodeFont);
    tb2.setFont(unicodeFont);
    tb3.setFont(unicodeFont);

    comboBox1 = new JComboBox(Constants.ENCODINGS.toArray());
    comboBox1.setActionCommand("comboBox1");
    comboBox1.setSelectedItem(Constants.ITRANS);
    comboBox1.addActionListener(this);

    comboBox2 = new JComboBox(Constants.ENCODINGS.toArray());
    comboBox2.setActionCommand("comboBox2");
    comboBox2.setSelectedItem(Constants.UNICODE_DVN);
    comboBox2.addActionListener(this);

    comboBox3 = new JComboBox(Constants.ENCODINGS.toArray());
    comboBox3.setActionCommand("comboBox3");
    comboBox3.setSelectedItem(Constants.IAST);
    comboBox3.addActionListener(this);

    /** *EXPERIMENT*** */
    textPane = new JTextPane();
    RTFEditorKit rtfkit = new RTFEditorKit();
    // HTMLEditorKit htmlkit = new HTMLEditorKit();
    textPane.setEditorKit(rtfkit); // set Kit which will read RTF Doc
    // textPane.setEditorKit(htmlkit);
    textPane.setEditable(false); // make uneditable
    textPane.setPreferredSize(new Dimension(200, 200));
    textPane.setText(""); // set

    p1.add(label1);
    p1a.add(comboBox1, BorderLayout.LINE_END);
    p1a.add(clipboardButton1, BorderLayout.LINE_START);

    p2.add(new JScrollPane(tb1));

    p3.add(label2);
    p3a.add(comboBox2, BorderLayout.LINE_END);
    p3a.add(clipboardButton2, BorderLayout.LINE_START);

    p4.add(new JScrollPane(tb2));

    p5.add(label3);
    p5a.add(comboBox3, BorderLayout.LINE_END);
    p5a.add(clipboardButton3, BorderLayout.LINE_START);

    p6.add(new JScrollPane(tb3));

    p6a.add(capitalize);
    p7.add(clearButton);
    p7.add(refreshButton);
    p7.add(exitButton);
    this.setJMenuBar(menubar);

    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));

    contentPane.add(p1);
    contentPane.add(p1a);
    contentPane.add(p2);
    contentPane.add(p3);
    contentPane.add(p3a);
    contentPane.add(p4);
    contentPane.add(p5);
    contentPane.add(p5a);
    contentPane.add(p6);
    contentPane.add(p6a);
    contentPane.add(p7);

}