Example usage for javax.swing JMenuItem addActionListener

List of usage examples for javax.swing JMenuItem addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:coolmap.module.impl.QuickStatModule.java

public QuickStatModule() {

    WidgetViewport viewport = WidgetMaster.getViewport();
    viewport.addPopupMenuSeparator(null);

    JMenuItem item = new JMenuItem("ANOVA(t-test)");
    item.addActionListener(new RowTest());
    viewport.addPopupMenuItem("Quick stat selected.../Row", item, false);

    item = new JMenuItem("ANOVA(t-test)");
    item.addActionListener(new ColumnTest());
    viewport.addPopupMenuItem("Quick stat selected.../Column", item, false);

}

From source file:it.unibas.spicygui.controllo.provider.intermediatezone.MyPopupProviderDeleteConst.java

private void createPopupMenu() {
    menu = new JPopupMenu("Popup menu");
    JMenuItem item;

    item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE));
    item.setActionCommand(DELETE);//from   www . j  a va 2s  .co  m
    item.addActionListener(this);
    menu.add(item);
}

From source file:Main.java

public Main() {
    JMenuBar bar = new JMenuBar();
    JMenu addMenu = new JMenu("Add");
    JMenuItem newFrame = new JMenuItem("Internal Frame");
    addMenu.add(newFrame);/*from  ww w .  j a v a  2  s  . co  m*/
    bar.add(addMenu);
    setJMenuBar(bar);

    final JDesktopPane theDesktop = new JDesktopPane();
    getContentPane().add(theDesktop);

    newFrame.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JInternalFrame frame = new JInternalFrame("Internal Frame", true, true, true, true);

            Container c = frame.getContentPane();
            MyJPanel panel = new MyJPanel();

            c.add(panel, BorderLayout.CENTER);
            frame.setSize(200, 200);
            frame.setOpaque(true);
            theDesktop.add(frame);
        }
    });

    setSize(500, 400);
    setVisible(true);
}

From source file:PreferencesTest.java

public PreferencesFrame() {
    // get position, size, title from preferences

    Preferences root = Preferences.userRoot();
    final Preferences node = root.node("/com/horstmann/corejava");
    int left = node.getInt("left", 0);
    int top = node.getInt("top", 0);
    int width = node.getInt("width", DEFAULT_WIDTH);
    int height = node.getInt("height", DEFAULT_HEIGHT);
    setBounds(left, top, width, height);

    // if no title given, ask user

    String title = node.get("title", "");
    if (title.equals(""))
        title = JOptionPane.showInputDialog("Please supply a frame title:");
    if (title == null)
        title = "";
    setTitle(title);//from ww  w .j av a2s.com

    // set up file chooser that shows XML files

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

    // accept all files ending with .xml
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".xml") || f.isDirectory();
        }

        public String getDescription() {
            return "XML files";
        }
    });

    // set up menus
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu menu = new JMenu("File");
    menuBar.add(menu);

    JMenuItem exportItem = new JMenuItem("Export preferences");
    menu.add(exportItem);
    exportItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showSaveDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    OutputStream out = new FileOutputStream(chooser.getSelectedFile());
                    node.exportSubtree(out);
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem importItem = new JMenuItem("Import preferences");
    menu.add(importItem);
    importItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (chooser.showOpenDialog(PreferencesFrame.this) == JFileChooser.APPROVE_OPTION) {
                try {
                    InputStream in = new FileInputStream(chooser.getSelectedFile());
                    Preferences.importPreferences(in);
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    JMenuItem exitItem = new JMenuItem("Exit");
    menu.add(exitItem);
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            node.putInt("left", getX());
            node.putInt("top", getY());
            node.putInt("width", getWidth());
            node.putInt("height", getHeight());
            node.put("title", getTitle());
            System.exit(0);
        }
    });
}

From source file:SiteFrame.java

public PageFrame(String name, SiteManager sm) {
    super("Page: " + name, true, true, true, true);
    parent = sm;//  w ww .  ja v  a  2s .co  m
    setBounds(50, 50, 300, 150);

    Container contentPane = getContentPane();

    // Create a text area to display the contents of our file in
    // and stick it in a scrollable pane so we can see everything
    ta = new JTextArea();
    JScrollPane jsp = new JScrollPane(ta);
    contentPane.add(jsp, BorderLayout.CENTER);

    JMenuBar jmb = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem saveItem = new JMenuItem("Save");
    saveItem.addActionListener(this);
    fileMenu.add(saveItem);
    jmb.add(fileMenu);
    setJMenuBar(jmb);

    filename = name;
    loadContent();
}

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   ww  w. j  av 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:DataExchangeTest.java

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

    // construct a File menu

    JMenuBar mbar = new JMenuBar();
    setJMenuBar(mbar);//from  w  ww . j av  a2  s . 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:AddButtonToTabBar.java

public AddButtonToTabBar() {
    super("Browser");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JMenuBar mb = new JMenuBar();
    JMenu mFile = new JMenu("File");
    JMenuItem mi = new JMenuItem("Add Tab");
    ActionListener addTabl = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addTab();/*from w  w  w .j a v  a  2 s  .c om*/
        }
    };
    mi.addActionListener(addTabl);
    mFile.add(mi);
    mb.add(mFile);
    setJMenuBar(mb);

    JPanel pnlURL = new JPanel();
    tp = new JTabbedPane();
    addTab();
    getContentPane().add(tp, BorderLayout.CENTER);

    lblStatus = new JLabel(" ");
    getContentPane().add(lblStatus, BorderLayout.SOUTH);

    setSize(300, 300);
    setVisible(true);
}

From source file:MenuShortcuts.java

MenuShortcuts(String s) {
    super("JMenuShortcuts: " + s);
    mb = new JMenuBar();
    setJMenuBar(mb); // Frame implements JMenuContainer

    Container cp = getContentPane();
    JMenuItem mi;
    // 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();/*  w w w .j  a va2 s . c om*/

    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:components.TabComponentsDemo.java

private void initMenu() {
    JMenuBar menuBar = new JMenuBar();
    //create Options menu
    tabComponentsItem = new JCheckBoxMenuItem("Use TabComponents", true);
    tabComponentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.ALT_MASK));
    tabComponentsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < pane.getTabCount(); i++) {
                if (tabComponentsItem.isSelected()) {
                    initTabComponent(i);
                } else {
                    pane.setTabComponentAt(i, null);
                }//from  w  ww  .j  av  a2s .c  o  m
            }
        }
    });
    scrollLayoutItem = new JCheckBoxMenuItem("Set ScrollLayout");
    scrollLayoutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
    scrollLayoutItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (pane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT) {
                pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
            } else {
                pane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
            }
        }
    });
    JMenuItem resetItem = new JMenuItem("Reset JTabbedPane");
    resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    resetItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            runTest();
        }
    });

    JMenu optionsMenu = new JMenu("Options");
    optionsMenu.add(tabComponentsItem);
    optionsMenu.add(scrollLayoutItem);
    optionsMenu.add(resetItem);
    menuBar.add(optionsMenu);
    setJMenuBar(menuBar);
}