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: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();/*  w ww  .  j av a  2s . 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:UndoStyleFrame.java

public UndoStyleFrame() {
    super();/* w  w w.java2s  .  c  o m*/
    setTitle("UndoStyleFrame");
    JTextPane textPane = new JTextPane();

    textPane.getDocument().addUndoableEditListener(undoAction);
    textPane.getDocument().addUndoableEditListener(redoAction);

    JMenu editMenu = new JMenu("Edit");
    editMenu.add(new JMenuItem(undoAction));
    editMenu.add(new JMenuItem(redoAction));

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(editMenu);

    setJMenuBar(menuBar);

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(new JButton(undoAction));
    buttonPanel.add(new JButton(redoAction));

    getContentPane().add(textPane, "Center");
    getContentPane().add(buttonPanel, "South");
}

From source file:Main.java

public Main() {
    setSize(450, 350);//from w ww  . j a  va 2  s .c o m
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(textfield, BorderLayout.SOUTH);

    JMenuBar mbar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.add(new JCheckBoxMenuItem("Check Me"));
    menu.addSeparator();
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(item);
    mbar.add(menu);
    setJMenuBar(mbar);

    JTabbedPane tabbedPane = new JTabbedPane();

    tabbedPane.addTab("Button", new TabIcon(), new JButton(""), "Click here for Button demo");
}

From source file:Popup.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);//from   ww w.j  a  v a2s . co m
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t.setText(((JMenuItem) e.getSource()).getText());
        }
    };
    JMenuItem m = new JMenuItem("Hither");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Yon");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Afar");
    m.addActionListener(al);
    popup.add(m);
    popup.addSeparator();
    m = new JMenuItem("Stay Here");
    m.addActionListener(al);
    popup.add(m);
    PopupListener pl = new PopupListener();
    addMouseListener(pl);
    t.addMouseListener(pl);
}

From source file:MenuTest.java

public MenuTest() {
    super();/*from w ww .j a  v a  2 s  .  c om*/

    MenuListener listener = new MenuListener() {
        public void menuCanceled(MenuEvent e) {
            dumpInfo("Canceled", e);
        }

        public void menuDeselected(MenuEvent e) {
            dumpInfo("Deselected", e);
        }

        public void menuSelected(MenuEvent e) {
            dumpInfo("Selected", e);
        }

        private void dumpInfo(String s, MenuEvent e) {
            JMenu menu = (JMenu) e.getSource();
            System.out.println(s + ": " + menu.getText());
        }
    };

    JMenu fileMenu = new JMenu("File");
    fileMenu.addMenuListener(listener);
    fileMenu.add(new JMenuItem("Open"));
    fileMenu.add(new JMenuItem("Close"));
    fileMenu.add(new JMenuItem("Exit"));
    JMenu helpMenu = new JMenu("Help");
    helpMenu.addMenuListener(listener);
    helpMenu.add(new JMenuItem("About MenuTest"));
    helpMenu.add(new JMenuItem("Class Hierarchy"));
    helpMenu.addSeparator();
    helpMenu.add(new JCheckBoxMenuItem("Balloon Help"));
    JMenu subMenu = new JMenu("Categories");
    subMenu.addMenuListener(listener);
    JRadioButtonMenuItem rb;
    ButtonGroup group = new ButtonGroup();
    subMenu.add(rb = new JRadioButtonMenuItem("A Little Help", true));
    group.add(rb);
    subMenu.add(rb = new JRadioButtonMenuItem("A Lot of Help"));
    group.add(rb);
    helpMenu.add(subMenu);
    JMenuBar mb = new JMenuBar();
    mb.add(fileMenu);
    mb.add(helpMenu);
    setJMenuBar(mb);
}

From source file:TabPanelwithImageIconCustom.java

public TabPanelwithImageIconCustom() {
    setSize(450, 350);/*from ww  w.j  a  v  a2  s .co m*/
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(textfield, BorderLayout.SOUTH);

    JMenuBar mbar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menu.add(new JCheckBoxMenuItem("Check Me"));
    menu.addSeparator();
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    menu.add(item);
    mbar.add(menu);
    setJMenuBar(mbar);

    JTabbedPane tabbedPane = new JTabbedPane();

    tabbedPane.addTab("Button", new TabIcon(), new JButton(""), "Click here for Button demo");
}

From source file:Main.java

public Main() {
    Icon icon = UIManager.getIcon("html.pendingImage");
    JTabbedPane jtb = new JTabbedPane();

    JPanel jplInnerPanel1 = createInnerPanel("Tab 1: Tooltip and Icon");
    jtb.addTab("One", icon, jplInnerPanel1, "Tab 1");
    jtb.setSelectedIndex(0);//from   www.  j  a  v a2s. c  om

    JPanel jplInnerPanel2 = createInnerPanel("Tab 2: Icon only");
    jtb.addTab("Two", icon, jplInnerPanel2);

    JPanel jplInnerPanel3 = createInnerPanel("Tab 3: Tooltip and Icon");
    jtb.addTab("Three", icon, jplInnerPanel3, "Tab 3");

    JPanel jplInnerPanel4 = createInnerPanel("Tab 4: Text only");
    jtb.addTab("Four", jplInnerPanel4);

    menu.add(new JMenuItem("Item 1"));
    menu.add(new JMenuItem("Item 2"));

    JLabel tab4Label = new JLabel();
    tab4Label.setText("Four");
    jtb.setTabComponentAt(3, tab4Label);
    tab4Label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            maybeShowPopup(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e) {
            jtb.getModel().setSelectedIndex(3);
            if (e.isPopupTrigger()) {
                menu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    setLayout(new GridLayout());
    add(jtb);
}

From source file:Test.java

public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuItem item = new JMenuItem("Test1");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Menu item Test1");
        }/*from   ww w  .jav  a 2  s .  c om*/
    });
    menu.add(item);

    item = new JMenuItem("Test2");
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Menu item Test2");
        }
    });
    menu.add(item);

    getContentPane().add(label);
    pack();
    setSize(300, 100);
}

From source file:Main.java

protected void showMenu(int x, int y) {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem mi = new JMenuItem("Delete");
    TreePath path = tree.getSelectionPath();
    Object node = path.getLastPathComponent();
    if (node == tree.getModel().getRoot()) {
        mi.setEnabled(false);//  www . j  av a 2  s. c  o  m
    }
    popup.add(mi);
    mi.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            deleteSelectedItems();
        }
    });
    popup.show(tree, x, y);
}

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

}