JMenu in Java Swing

Home  »  Java  »  Advance Java  »  Java Swing II  »  JMenu


The menu component in swing enables you to list various available options. JMenuBar in swing is set on the top area of the Window displaying the GUI for a Java application. A menu bar contains one or more menus with a number of menu items. Swing enables you to add icons, check boxes and radio buttons as menu items. The below figure shows the hirerarchy of menu components that swing supports:



All the JMenu components inherit from the JCOmpoent class of Java. The syntax to create a JMenuBar in Java Swing is:



A JMenuBar is set on the top of the container used for containing various components of a GUI. The syntax to set a JMenuBar at the top of the container is:



The syntax to create various menu and add the menu to the JMenuBar is:



The syntax to create menu items is:



The syntax to create a JMenuItem with icons associated with it is:



Consider the following example, which shows the use of JMenu to create a menu that displays icons with each menu ites:



C:\>jdk1.4\bin>javac JMenuDemo.java
C:\>jdk1.4\bin>java JMenuDemo


Displaying JMenu in Swing


Download Complete Program

  -    -  JMenu's Icons



Java Swing-II


JOptionPane Class Input Dialog Boxes JSliders
JProgressBars JTables JTabbedPane
JMenu JPopupMenu JToolBar
JFileChooser JScrollBar JScrollPane
JRootPane JTextPane JTree
JSplitPane JDesktopPane JEditorPane




1 comment: