Results 1 to 3 of 3
  1. #1
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default JPopupMenu confusion

    Hello. I am trying to use a JPopupMenu to perform some tasks. Some things I can't figure out how to do are: I can't seem to figure out how to tell what option a user clicks. I've looked through the doc countless times but just don't see what I am looking for, or if I am then I just can't interpret it properly. Keep in mind I copy and pasted this JPopupMenu and fiddled with it just a little bit so I barely understand how it works.

    In this code that I am about to show you, the variable "movieList" is the name of a JList that I have.

    Java Code:
    final JPopupMenu Pmenu;
                JMenuItem menuItem;
                
                Pmenu = new JPopupMenu();
    		menuItem = new JMenuItem("Check out");
    		Pmenu.add(menuItem);
    		menuItem = new JMenuItem("Check in");
    		Pmenu.add(menuItem);
    		menuItem = new JMenuItem("Reserve");
    		Pmenu.add(menuItem);
    		menuItem.addActionListener(new ActionListener(){
                @Override
    			public void actionPerformed(ActionEvent e){}
    			});
    		movieList.addMouseListener(new MouseAdapter(){
                @Override
    			public void mousePressed(MouseEvent me){
    				if(me.isPopupTrigger()){
    					Pmenu.show(me.getComponent(), me.getX(), me.getY());
    				}
                                    
    			}
                @Override
    			public void mouseReleased(MouseEvent Me){
    				if(Me.isPopupTrigger()){
    					Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
    				}
    			}
    		});
    Any help would be greatly appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: JPopupMenu confusion

    Could you post a small program that compiles, executes and shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Reeling is offline Member
    Join Date
    Jan 2012
    Posts
    49
    Rep Power
    0

    Default Re: JPopupMenu confusion

    I figured it out. What I was looking for was an actionEventListener. I wasn't familiar with what an action was so it was kind of confusing to figure out. Thanks anyway!

Similar Threads

  1. JPopupMenu not hiding
    By macwadu in forum AWT / Swing
    Replies: 8
    Last Post: 03-02-2011, 10:43 AM
  2. JTextField in a JPopupMenu
    By baran_khan in forum AWT / Swing
    Replies: 6
    Last Post: 05-02-2009, 10:43 PM
  3. JMenu to JPopupMenu
    By carderne in forum New To Java
    Replies: 0
    Last Post: 02-28-2009, 07:07 PM
  4. JPopupMenu
    By hungleon88 in forum NetBeans
    Replies: 8
    Last Post: 01-15-2009, 06:00 PM
  5. JPopupMenu problem
    By sylvievdb in forum AWT / Swing
    Replies: 3
    Last Post: 10-06-2008, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •