Example usage for javax.swing JMenu add

List of usage examples for javax.swing JMenu add

Introduction

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

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Creates a new menu item attached to the specified Action object and appends it to the end of this menu.

Usage

From source file:Main.java

public Main() {
    setTitle("ZipTest");
    setSize(300, 400);// www. j  a v  a2 s .  co  m

    JMenuBar mbar = new JMenuBar();
    JMenu m = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    m.add(openItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    m.add(exitItem);
    mbar.add(m);

    Container contentPane = getContentPane();
    contentPane.add(mbar, "North");
}

From source file:FileChooserDemo.java

public FileChooserDemo() {
    setTitle("ZipTest");
    setSize(300, 400);/*from  www  . j  ava 2  s  . co m*/

    JMenuBar mbar = new JMenuBar();
    JMenu m = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    m.add(openItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    m.add(exitItem);
    mbar.add(m);

    Container contentPane = getContentPane();
    contentPane.add(mbar, "North");
}

From source file:ImageViewer.java

public ImageViewer() {
    setTitle("ImageViewer");
    setSize(300, 400);/*from   w w w.  j  av  a  2  s  . c o m*/

    JMenuBar mbar = new JMenuBar();
    JMenu m = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    m.add(openItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    m.add(exitItem);
    mbar.add(m);
    setJMenuBar(mbar);

    label = new JLabel();
    Container contentPane = getContentPane();
    contentPane.add(label, "Center");
}

From source file:MainClass.java

public MainClass() {
    super();//w  w  w . j a  v  a2s .c om

    setChannel(currentNumber);

    numberLabel.setHorizontalAlignment(JLabel.CENTER);
    numberLabel.setFont(new Font("Serif", Font.PLAIN, 32));

    getContentPane().add(numberLabel, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16));
    getContentPane().add(buttonPanel, BorderLayout.CENTER);
    buttonPanel.add(new JButton(upAction));
    buttonPanel.add(new JButton(gotoFavoriteAction));
    buttonPanel.add(new JButton(downAction));
    buttonPanel.add(new JButton(setFavoriteAction));

    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Number");
    menu.add(new JMenuItem(upAction));
    menu.add(new JMenuItem(downAction));
    menu.addSeparator();
    menu.add(new JMenuItem(gotoFavoriteAction));
    menu.add(new JMenuItem(setFavoriteAction));
    mb.add(menu);
    setJMenuBar(mb);
}

From source file:ToolBarExample.java

public ToolBarExample() {
    menuBar = new JMenuBar();

    // Create a set of actions to use in both the menu and toolbar
    DemoAction leftJustifyAction = new DemoAction("Left", new ImageIcon("1.gif"), "Left justify text", 'L');
    DemoAction rightJustifyAction = new DemoAction("Right", new ImageIcon("2.gif"), "Right justify text", 'R');
    DemoAction centerJustifyAction = new DemoAction("Center", new ImageIcon("3.gif"), "Center justify text",
            'M');
    DemoAction fullJustifyAction = new DemoAction("Full", new ImageIcon("4.gif"), "Full justify text", 'F');

    JMenu formatMenu = new JMenu("Justify");
    formatMenu.add(leftJustifyAction);
    formatMenu.add(rightJustifyAction);// w w  w .  ja  v  a2 s .c  om
    formatMenu.add(centerJustifyAction);
    formatMenu.add(fullJustifyAction);

    menuBar.add(formatMenu);

    toolBar = new JToolBar("Formatting");
    toolBar.add(leftJustifyAction);
    toolBar.add(rightJustifyAction);
    toolBar.add(centerJustifyAction);
    toolBar.add(fullJustifyAction);

    toolBar.addSeparator();
    JLabel label = new JLabel("Font");
    toolBar.add(label);

    toolBar.addSeparator();
    JComboBox combo = new JComboBox(fonts);
    combo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0,
                        "Font [" + ((JComboBox) e.getSource()).getSelectedItem() + "] chosen!\n", null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });
    toolBar.add(combo);

    //  Disable one of the Actions
    fullJustifyAction.setEnabled(false);
}

From source file:Main.java

private JMenu getDialogMenu() {
    JMenu myMenu = new JMenu("Dialogs");
    JMenuItem myItem = new JMenuItem("Information");
    myItem.addActionListener(this);
    myMenu.add(myItem);
    myItem = new JMenuItem("Warning");
    myItem.addActionListener(this);
    myMenu.add(myItem);/*from   w w w  . j a v a  2s.  c  o  m*/
    myItem = new JMenuItem("Error");
    myItem.addActionListener(this);
    myMenu.add(myItem);
    myItem = new JMenuItem("Plain");
    myItem.addActionListener(this);
    myMenu.add(myItem);
    return myMenu;
}

From source file:ActionExampleSwing.java

public ActionExampleSwing() {
    super("ActionExample Swing");

    setChannel(currentChannel); // enable/disable the Actions as appropriate

    channelLabel.setHorizontalAlignment(JLabel.CENTER);
    channelLabel.setFont(new Font("Serif", Font.PLAIN, 32));

    getContentPane().add(channelLabel, BorderLayout.NORTH);

    JPanel buttonPanel = new JPanel(new GridLayout(2, 2, 16, 6));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(6, 16, 16, 16));
    getContentPane().add(buttonPanel, BorderLayout.CENTER);
    buttonPanel.add(new JButton(upAction));
    buttonPanel.add(new JButton(gotoFavoriteAction));
    buttonPanel.add(new JButton(downAction));
    buttonPanel.add(new JButton(setFavoriteAction));

    JMenuBar mb = new JMenuBar();
    JMenu menu = new JMenu("Channel");
    menu.add(new JMenuItem(upAction));
    menu.add(new JMenuItem(downAction));
    menu.addSeparator();/*  w  w w.  j  a va2  s. co m*/
    menu.add(new JMenuItem(gotoFavoriteAction));
    menu.add(new JMenuItem(setFavoriteAction));
    mb.add(menu);
    setJMenuBar(mb);
}

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   ww w  .  j  a  va 2  s  . c  om
            }
        }
    });
    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);
}

From source file:org.pgptool.gui.ui.keyslist.KeysListView.java

private void initMenuBar() {
    menuBar = new JMenuBar();
    JMenu menuTs = new JMenu(Messages.get("term.actions"));
    menuTs.add(miImport = new JMenuItem());
    menuTs.add(miCreate = new JMenuItem());
    menuTs.addSeparator();/*from   w  w  w. j a va  2  s  .  com*/
    menuTs.add(miExportPublicKeys = new JMenuItem());
    menuTs.addSeparator();
    menuTs.add(miClose = new JMenuItem());
    menuBar.add(menuTs);
}

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

/**
 *  Adds a separator at the end of the menu.
 *//*w  ww. ja  v a 2s.  c  o  m*/
Menu addSeparator() {
    JMenu lastMenu = getMenu(getMenuCount() - 1);
    lastMenu.add(new JSeparator());
    return this;
}