Results 1 to 5 of 5
  1. #1
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default Returning the selected menu item from a popup screen

    Hi. I'm having trouble returning what item has been seect from a popup window.
    When I right click I get my menu-popup, but when I click on a menu item I get nothing.

    I've added an action listener to the popup menu. My menu is a sub-menu and I'm trying to get information back from my sub menu.

    Any tips please?

    Thanks

  2. #2
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default

    Opps sorted it :-D

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please mark the thread "solved" (see thread tools above), and please provide a brief synopsis of your solution. Thanks.

  4. #4
    phil128 is offline Member
    Join Date
    Sep 2008
    Posts
    40
    Rep Power
    0

    Default

    private JMenu _createSubMenu(){
    _subMenu = new JMenu("Replace");

    for(int n = 1; n!= 5; n++){
    _subMenu.add("Pad "+ String.valueOf(n));
    _subMenu.getItem(n-1).addActionListener(this);
    }

    return _subMenu;
    }

    I didn't add an action listener to EACH of the menu items :-D.
    Last edited by phil128; 12-11-2010 at 06:01 PM. Reason: Solution to my problem

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by phil128 View Post
    I didn't add an action listener to EACH of the menu items :-D.
    Thanks for posting this information. Let me repost your code with code tags:

    Java Code:
    	private JMenu _createSubMenu(){
    		subMenu = new JMenu("Replace");
    
    		for(int n = 1; n!= 5; n++){
    			subMenu.add("Pad "+ String.valueOf(n));
    			subMenu.getItem(n-1).addActionListener(this);
    		}
    		
    		return _subMenu;
    	}

Similar Threads

  1. popup menu
    By jperson in forum New To Java
    Replies: 3
    Last Post: 09-18-2010, 02:44 PM
  2. Replies: 0
    Last Post: 07-13-2010, 10:16 AM
  3. How to get the selected item from combox
    By man4ish in forum AWT / Swing
    Replies: 5
    Last Post: 12-30-2009, 11:29 AM
  4. SELECTED select menu??
    By Samurai Coder in forum New To Java
    Replies: 1
    Last Post: 12-03-2009, 07:09 PM
  5. Replies: 7
    Last Post: 05-09-2008, 08:54 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
  •