Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Java: JMenu

JavaFAQ Home » Swing, AWT Go to all tips in Swing, AWT

Bookmark and Share

A menu bar can be added to the top of any top-level containers ( JFrame, JApplet, JDialog, and less commonly JInternalFrame, JRootPane). Note that it can not be added to JPanel.

Think of a menu as a way to arrange buttons.

Types of menus

  • Dropdown menus hang down from the menu bar at the top of a window.
  • Popup menus appear when the user clicks, eg with the right mouse button, on a component that can handle a popup request.
  • Combo boxes are like menus that always shows one item. Similary, there are lists and radio buttons.

JMenuBar, JMenu, and JMenuItem

Dropdown menus have three parts:

  1. JMenuBar is positioned across the top of a container (eg a JFrame, JPanel, or JApplet). It's placed above the content pane, so does not use the container's layout. Add menus to the menubar.
  2. JMenu is a vertical list of menu items.
  3. JMenuItem and Separators are added to each menu. Menu items are usually strings, but can also have icons, checkboxes, or hierarchical submenus.

Menus and Menu Items are Buttons!

It is easy to see how menu items are buttons that appear when a menu appears. But the menu names in the menu bar are also buttons. When you press on these "buttons", they create a popup menu that you see as a dropdown menu.


See MenuDemo.java.

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy