Example usage for javax.swing JFrame setJMenuBar

List of usage examples for javax.swing JFrame setJMenuBar

Introduction

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

Prototype

@BeanProperty(bound = false, hidden = true, description = "The menubar for accessing pulldown menus from this frame.")
public void setJMenuBar(final JMenuBar menubar) 

Source Link

Document

Sets the menubar for this frame.

Usage

From source file:CheckMenuItem.java

public static void main(String[] args) {
    final JLabel statusbar = new JLabel(" Statusbar");

    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);

    JMenu view = new JMenu("View");
    view.setMnemonic(KeyEvent.VK_V);

    JCheckBoxMenuItem sbar = new JCheckBoxMenuItem("Show StatuBar");
    sbar.setState(true);//from w  w w .j a v a2  s .  c o m

    sbar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (statusbar.isVisible()) {
                statusbar.setVisible(false);
            } else {
                statusbar.setVisible(true);
            }
        }
    });

    view.add(sbar);

    menubar.add(file);
    menubar.add(view);

    JFrame f = new JFrame();
    f.setJMenuBar(menubar);
    statusbar.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
    f.add(statusbar, BorderLayout.SOUTH);
    f.setSize(360, 250);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Create the menu bar
    JMenuBar menuBar = new JMenuBar();

    // Create a menu
    JMenu menu = new JMenu("Menu Label");
    menuBar.add(menu);/*from w  ww.  ja  v  a2s  . c o m*/

    // Create a menu item
    JMenuItem item = new JMenuItem("Item Label");
    //item.addActionListener(actionListener);
    menu.add(item);

    JFrame frame = new JFrame();
    // Install the menu bar in the frame
    frame.setJMenuBar(menuBar);
}

From source file:AboutDialog.java

public static void main(String[] args) {
    JMenuBar menubar = new JMenuBar();

    JMenu file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);

    JMenu help = new JMenu("Help");
    help.setMnemonic(KeyEvent.VK_H);

    JMenuItem about = new JMenuItem("About");
    help.add(about);//from   w w w  . j  av  a  2s . c  o m

    about.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AboutDialog ad = new AboutDialog();
            ad.setVisible(true);
        }
    });

    menubar.add(file);
    menubar.add(help);
    JFrame f = new JFrame();
    f.setJMenuBar(menubar);

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String s[]) {
    Main example = new Main();
    JFrame frame = new JFrame("Menu Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(example.menuBar);
    frame.pack();//from   w  w w  .j  a va2  s  .  com
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea ta = new JTextArea();
    ta.setLineWrap(true);/*from  w  ww. ja v  a 2 s. c o m*/

    Action[] actions = ta.getActions();
    JMenuBar menubar = new JMenuBar();
    JMenu actionmenu = new JMenu("Actions");
    menubar.add(actionmenu);

    JMenu firstHalf = new JMenu("1st Half");
    JMenu secondHalf = new JMenu("2nd Half");
    actionmenu.add(firstHalf);
    actionmenu.add(secondHalf);

    int mid = actions.length / 2;
    for (int i = 0; i < mid; i++) {
        firstHalf.add(actions[i]);
    }
    for (int i = mid; i < actions.length; i++) {
        secondHalf.add(actions[i]);
    }

    // Show it . . .
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(ta);
    f.setJMenuBar(menubar);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:SimpleToolbar.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    JMenuBar menubar = new JMenuBar();
    JMenu file = new JMenu("File");
    menubar.add(file);/*from w  ww  .j a  v a  2 s .  co  m*/
    f.setJMenuBar(menubar);

    JToolBar toolbar = new JToolBar();
    ImageIcon icon = new ImageIcon("exit.png");
    JButton exit = new JButton(icon);
    toolbar.add(exit);
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });

    f.add(toolbar, BorderLayout.NORTH);
    f.setSize(300, 200);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String s[]) {
    Main example = new Main();
    example.pane = new JTextPane();
    example.pane.setPreferredSize(new Dimension(250, 250));
    example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(example.menuBar);
    frame.getContentPane().add(example.pane, BorderLayout.CENTER);
    frame.pack();//ww w .j av a  2s  . c o  m
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String s[]) {

    MainClass example = new MainClass();
    example.pane = new JTextPane();
    example.pane.setPreferredSize(new Dimension(250, 250));
    example.pane.setBorder(new BevelBorder(BevelBorder.LOWERED));

    JFrame frame = new JFrame("Menu Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(example.menuBar);
    frame.getContentPane().add(example.pane, BorderLayout.CENTER);
    frame.pack();/*from w  w  w.  j  a  va 2s . c  om*/
    frame.setVisible(true);
}

From source file:MenuActionExample.java

public static void main(String s[]) {
    MenuActionExample example = new MenuActionExample();
    JFrame frame = new JFrame("Action Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(example.menuBar);
    frame.getContentPane().add(example.toolBar, BorderLayout.NORTH);
    frame.setSize(200, 200);//from  www.j a  va  2s .c  om
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    Main mainPanel = new Main();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(mainPanel);/* w  w w .  j  a va  2s.  c o  m*/
    f.setJMenuBar(mainPanel.createMenuBar());
    f.pack();
    f.setVisible(true);
}