Results 1 to 5 of 5

Thread: Creating a Popup Menu in java

  1. #1
    Join Date
    Nov 2009
    Posts
    712

    Creating a Popup Menu in java

    Hello, I am learning java programming language and while learning it, I want to create a popup menu with the help of java programming language. If you are having any solution program which will help me to get it, then please provide that to me. I will be thankful to you. Please reply me as soon as possible.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Creating a Popup Menu in java

    Hello, if you want to get the solution for your problem then you need to make use of the line of code below:
    Code:
    JMenuItem menuitem = new JMenuItem("Item Label"); 
    menuitem.addActionListener(actionListener); 
    menu.add(menuitem); 
    cmp.addMouseListener(new MouseAdapter() 
    { 
    public void mousePressed(MouseEvent me)
     { 
    if (me.isPopupTrigger()) 
    {
     menu.show(me.getComponent(), me.getX(), me.getY()); 
    } 
    } 
    public void mouseReleased(MouseEvent me) 
    { 
    if (me.isPopupTrigger()) 
    { 
    menu.show(me.getComponent(), me.getX(), me.getY()); 
    }
     }
     });

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Creating a Popup Menu in java

    Hey, if you wan to create a popup menu in java then you just need to use the class and methods below in your program and get your problem solved:
    Classes:

    • JPopupMenu:
    • mouseReleased

    Methods:

    • isPopupTrigger()
    • getX()
    • getY()
    • show(me.getComponent(), me.getX(), me.getY())
    • getComponent()

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Creating a Popup Menu in java

    Hello, I have a code below which will simply provide you solution for the creating a popup menu in java.
    Code:
    import javax.swing.*;
    import java.awt.event.*;
    
    public class PopUpmenu
    {
      JPopupmenu jpopupmenu;
      JmenuItem jmenuItem;
      public static void main(String[] args) 
    {
        PopUpmenu obj = new PopUpmenu();
      }
    
      public PopUpmenu()
    {
        JFrame frm = new JFrame("Create Popup menu");
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jpopupmenu = new JPopupmenu();
        jmenuItem = new JmenuItem("Check");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Edit");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Remove");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Test");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Done");
        jpopupmenu.add(jmenuItem);
        jmenuItem.addActionListener(new ActionListener()
    {
          public void actionPerformed(ActionEvent e)
    {
    }
          });
        frm.addMouseListener(new MouseAdapter()
    {
          public void mouseReleased(MouseEvent me)
    {
            if(me.isPopupTrigger())
    {
              jpopupmenu.show(me.getComponent(), me.getX(), me.getY());
            }
          }
        });
        frm.setSize(400,400);
        frm.setVisible(true);
      }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Creating a Popup Menu in java

    Hello, I think you need to make use of the following source code for solving the problem of your popup menu creation in java:

    Code:
    public class PopUpmenu
    {
      JPopupmenu jpopupmenu;
      JmenuItem jmenuItem;
      public static void main(String[] args) 
    {
        PopUpmenu obj = new PopUpmenu();
      }
    
      public PopUpmenu()
    {
        JFrame frm = new JFrame("Create Popup menu");
        frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jpopupmenu = new JPopupmenu();
        jmenuItem = new JmenuItem("Check");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Edit");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Remove");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Test");
        jpopupmenu.add(jmenuItem);
        jmenuItem = new JmenuItem("Done");
        jpopupmenu.add(jmenuItem);
        jmenuItem.addActionListener(new ActionListener()
    {
          public void actionPerformed(ActionEvent e)
    {
    }
          });
        frm.addMouseListener(new MouseAdapter()
    {
          public void mouseReleased(MouseEvent me)
    {
            if(me.isPopupTrigger())
    {
              jpopupmenu.show(me.getComponent(), me.getX(), me.getY());
            }
          }
        });
        frm.setSize(400,400);
        frm.setVisible(true);
      }
    }

Similar Threads

  1. popup menu in Firefox hosed when used on Mac
    By Jagathi in forum Technology & Internet
    Replies: 7
    Last Post: 29-06-2011, 09:12 PM
  2. Creating a Popup with Fireworks 4
    By Aidan 12 in forum Windows Software
    Replies: 3
    Last Post: 06-03-2011, 08:11 AM
  3. Replies: 1
    Last Post: 14-04-2009, 01:45 PM
  4. How do I make a menu popup from a CommandButton?
    By RadhaV in forum Software Development
    Replies: 4
    Last Post: 27-02-2009, 05:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,579,901.20856 seconds with 17 queries