Sponsered Links
Categories
Sponsered Links

Swing JMenu Example

 

In this example, you will see, how to create menus in Swing. Menu bar contains a collection of menus. Here we create four menu that is: "File", "Edit", "View" and "Help". The complete program code and output is as follows:

Sample code (SwingJMenu.java):

import javax.swing.*;

public class SwingJMenu extends JFrame {
  private JMenuBar menuBar = new JMenuBar();

  public SwingJMenu(String title) {
    setTitle(title);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setJMenuBar(menuBar);
    JMenu fileMenu = new JMenu("File");
    JMenu editMenu = new JMenu("Edit");
    JMenu viewMenu = new JMenu("View");
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(viewMenu);
    menuBar.add(helpMenu);
  }

  public static void main(String[] args) {
    SwingJMenu window = new SwingJMenu("Menu"); 
    window.setBounds(3030300300);
    window.setVisible(true);
  }
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved