Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Create a Popup Menus with Nested Menus in Java

                         

In this section, you will learn how to create a nested popup menu in Java Swing. When you click the right mouse button on the frame then you get a popup menu. Here, you will show multiple menu items like: line up icon, refresh, properties and new in the list of the menu which represents the popup menu. The new menu item have another popup menu which contains items like: folder, text document and shortcut. Following figure shows the nested popup menu:

Nested Pop Up Menu in Swing Application

createMenu(String):
This method has been used to create a nested list of menus for the 'New' menu item from the main popup menu list. 

Here is the code of program:

import javax.swing.*;
import java.awt.event.*;

public class NestedPopupMenu{
  JPopupMenu Pmenu;
  JMenuItem Mitem;
  public static void main(String[] args) {
    NestedPopupMenu n = new NestedPopupMenu();
  }

  public  NestedPopupMenu(){
    JFrame frame = new JFrame("Creating a Popup Menu with Nested Menus");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Pmenu = new JPopupMenu();
    Mitem = new JMenuItem("Line Up Icon");
    Pmenu.add(Mitem);
    Mitem = new JMenuItem("Refresh");
    Pmenu.add(Mitem);
    Mitem = new JMenuItem("Properties");
    Pmenu.add(Mitem);
    Pmenu.add(createMenu("New"));
    frame.addMouseListener(new MouseAdapter(){
      public void mouseReleased(MouseEvent Me){
        if(Me.isPopupTrigger()){
          Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
        }
      }
    });
    frame.setSize(400,400);
    frame.setVisible(true);
  }

  public JMenu createMenu(String title){
    JMenu m = new JMenu(title);
    m.add("Folder");
    m.add("Text Document");
    m.add("Shortcut");
    return m;
  }
}

Download this example

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
calling one jsp p
pagination using javas
data grid
draw Flag
types of webserver
Photoshop Textures and
java 4 features
JSON AJAX
array element
Creating Midlet Applic
convert java.sql.Time
meterbar bean
xls
php oops
json lib/componen...]=
Photoshop Web Layouts
paging and sorting wit
combo box my sql
stored procedure debug
connection pooling usi
logout code in jsp
JSF tree collapse
log4j
clear grid dojo
LRU
scroll bar
java merging images
tree
jersey
example of JFileChoos
retreive numerical val
Selection Sort In Java
jtabbedpanel enabled
Image with mouse drag
Photoshop Text Effects
VB Project
Telephony
message box display in
Binome
Authentication Filters
how to iterate a linke
compare two arraylist
jsf tree node set hr
get url
ajax auto complete
jar entry
diff. shape of linear
advantages of jsp over
jsp method
Struts Projects
tax calculator
Passing Parameters in
FlowLayout
JDBC-ODBC
<form: checkbox path=
Treemap using gwt tree
draw Polyline
comparable
jsp with strutsframewo
selecting option value
struts-servlets.xml
generate report in exc
FIFO
java example program t
how to write in pdf us
Insert an array list o
program in java to ins
IBM MQ server
Hibernate Min() Functi
increase size of strut
JConfig
java drivers use to co
Java Mysql
send email
Javascript Date and Ti
dojo debug
code to add and retriv
source code for edit e
explaination of JDBC u
how retrive a data fro
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.