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

License:asdf

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//from   w  w w .  j a v  a2s  . c  o  m

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("asdf");
    fileMenu.add(newMenuItem);

    newMenuItem.addMenuKeyListener(new MenuKeyListener() {

        public void menuKeyTyped(MenuKeyEvent e) {
            System.out.println("KeyTyped");
        }

        public void menuKeyPressed(MenuKeyEvent e) {
            System.out.println("KeyPressed");
        }

        public void menuKeyReleased(MenuKeyEvent e) {
            System.out.println("KeyReleased");
        }
    });

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:RadioButtonMenuSample.java

public static void main(String args[]) {
    JFrame f = new JFrame("JRadioButtonMenuItem Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Options");
    menu.setMnemonic(KeyEvent.VK_O);

    ButtonGroup group = new ButtonGroup();

    JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem("North");
    group.add(menuItem);//from  w  ww  .  j  a  v a2  s  .  c om
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("East");
    group.add(menuItem);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("West");
    group.add(menuItem);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("South");
    group.add(menuItem);
    menu.add(menuItem);

    menuItem = new JRadioButtonMenuItem("Center");
    group.add(menuItem);
    menu.add(menuItem);

    bar.add(menu);
    f.setJMenuBar(bar);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);//  w  w w  . j av a 2  s.  c o  m

    MenuListener lis = new MenuListener() {

        public void menuSelected(MenuEvent e) {
            System.out.println("menuSelected");
        }

        public void menuDeselected(MenuEvent e) {
            System.out.println("menuDeselected");

        }

        public void menuCanceled(MenuEvent e) {
            System.out.println("menuCanceled");

        }
    };

    fileMenu.addMenuListener(lis);

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New");
    fileMenu.add(newMenuItem);

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);

    fileMenu.removeMenuListener(lis);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setUndecorated(true);// w  w  w. j a v  a2  s  . c  om
    frame.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            point.x = e.getX();
            point.y = e.getY();
        }
    });
    frame.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            Point p = frame.getLocation();
            frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y);
        }
    });

    frame.setSize(300, 300);
    frame.setLocation(200, 200);
    frame.setLayout(new BorderLayout());

    frame.getContentPane().add(new JLabel("Drag to move", JLabel.CENTER), BorderLayout.CENTER);

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menuBar.add(menu);
    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(e -> System.exit(0));
    menu.add(item);
    frame.setJMenuBar(menuBar);
    frame.setVisible(true);
}

From source file:ContructMenuMenuDragMouseListener.java

License:asdf

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);/*w ww . j  a va2  s  .c  o  m*/

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("asdf");
    fileMenu.add(newMenuItem);

    newMenuItem.addMenuDragMouseListener(new MenuDragMouseListener() {

        public void menuDragMouseEntered(MenuDragMouseEvent e) {
            System.out.println("menuDragMouseEntered");
        }

        public void menuDragMouseExited(MenuDragMouseEvent e) {
            System.out.println("menuDragMouseExited");

        }

        public void menuDragMouseDragged(MenuDragMouseEvent e) {
            System.out.println("menuDragMouseDragged");

        }

        public void menuDragMouseReleased(MenuDragMouseEvent e) {
            System.out.println("menuDragMouseReleased");

        }
    });

    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);//from w w  w . j  a  v  a2  s  . co m

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive");
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            String newLabel;
            if (selected) {
                newLabel = "A";
            } else {
                newLabel = "B";
            }
            aButton.setText(newLabel);
        }
    };

    caseMenuItem.addActionListener(aListener);
    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:CheckBoxSample.java

public static void main(String args[]) {

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            String newLabel;/*from  w  w w.j  av a 2s .  c  o m*/
            Icon newIcon;
            if (selected) {
                newLabel = "Girl";
                newIcon = girlIcon;
            } else {
                newLabel = "Boy";
                newIcon = boyIcon;
            }
            aButton.setText(newLabel);
            aButton.setIcon(newIcon);
        }
    };

    ItemListener iListener = new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            int state = event.getStateChange();
            String newLabel;
            Icon newIcon;
            if (state == ItemEvent.SELECTED) {
                newLabel = "Girl";
                newIcon = girlIcon;
            } else {
                newLabel = "Boy";
                newIcon = boyIcon;
            }
            aButton.setText(newLabel);
            aButton.setIcon(newIcon);
        }
    };

    JFrame frame = new JFrame("CheckBox Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    menu.setMnemonic(KeyEvent.VK_M);
    JCheckBoxMenuItem one = new JCheckBoxMenuItem();
    menu.add(one);
    JCheckBoxMenuItem two = new JCheckBoxMenuItem("Boy");
    menu.add(two);
    JCheckBoxMenuItem three = new JCheckBoxMenuItem(boyIcon);
    menu.add(three);
    JCheckBoxMenuItem four = new JCheckBoxMenuItem("Girl", true);
    menu.add(four);
    JCheckBoxMenuItem five = new JCheckBoxMenuItem("Boy", boyIcon);
    five.addItemListener(iListener);
    menu.add(five);
    Icon stateIcon = new DiamondAbstractButtonStateIcon(Color.black);

    UIManager.put("CheckBoxMenuItem.checkIcon", stateIcon);
    JCheckBoxMenuItem six = new JCheckBoxMenuItem("Girl", girlIcon, true);
    six.addActionListener(aListener);
    menu.add(six);

    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:lcmc.LCMC.java

/** The main function for starting the application. */
public static void main(final String[] args) {
    Tools.init();//  w w w. ja  v  a2s .  c  om
    final JFrame mainFrame = new JFrame(Tools.getString("DrbdMC.Title") + " " + Tools.getRelease());
    final List<Image> il = new ArrayList<Image>();
    for (final String iconS : new String[] { "LCMC.AppIcon32", "LCMC.AppIcon48", "LCMC.AppIcon64",
            "LCMC.AppIcon128", "LCMC.AppIcon256" }) {
        il.add(Tools.createImageIcon(Tools.getDefault(iconS)).getImage());
    }
    mainFrame.setIconImages(il);
    final String autoArgs = initApp(args);
    mainFrame.setGlassPane(getMainGlassPane());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.addWindowListener(new ExitListener());
    mainFrame.setJMenuBar(getMenuBar());
    mainFrame.setContentPane(getMainPanel());
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            createAndShowGUI((Container) mainFrame);
        }
    });
    if (autoArgs != null) {
        Tools.parseAutoArgs(autoArgs);
    }
    //final Thread t = new Thread(new Runnable() {
    //    public void run() {
    //        drbd.utilities.RoboTest.startMover(600000, true);
    //    }
    //});
    //t.start();
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);//from   ww  w.  ja  va  2s.  c  o m

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    newMenuItem.setArmed(false);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive");
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            String newLabel;
            if (selected) {
                newLabel = "A";
            } else {
                newLabel = "B";
            }
            aButton.setText(newLabel);
        }
    };

    caseMenuItem.addActionListener(aListener);
    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("MenuSample Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar menuBar = new JMenuBar();

    // File Menu, F - Mnemonic
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);//  ww w . j  av  a2  s . com

    // File->New, N - Mnemonic
    JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N);
    newMenuItem.setEnabled(false);
    fileMenu.add(newMenuItem);

    JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive");
    caseMenuItem.setMnemonic(KeyEvent.VK_C);
    fileMenu.add(caseMenuItem);

    ActionListener aListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            String newLabel;
            if (selected) {
                newLabel = "A";
            } else {
                newLabel = "B";
            }
            aButton.setText(newLabel);
        }
    };

    caseMenuItem.addActionListener(aListener);
    frame.setJMenuBar(menuBar);
    frame.setSize(350, 250);
    frame.setVisible(true);
}