Results 1 to 1 of 1
  1. #1
    sairus is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default JMenu and ActionListener

    Why ActionListener works for JMenuItem, for JMenu no?
    Java Code:
    Listener listen = new Listener();
    String[] mmName = {"File","etc"};
    /**...**/
    for (int i=0; i<mmName.length; i++){
    		 mm[i]=new JMenu(mmName[i]); //mmName[i] - String[]
    		 mm[i].addActionListener(listen);
    }
    /**...**/
    public class Listener extends setOfMethods implements ActionListener{
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		cmd = e.getActionCommand();
    /**...**/
               }
    }
    thanks

    UPD: I solved this. I insert in JMenuBar JMenuItem, not a JMenu. And for JMenuItem add action listener. Looks little strange but working :) And looks more better than insert Jbutton in JMenu.
    PS: Sorry for English :o
    Last edited by sairus; 02-23-2011 at 12:56 AM.

Similar Threads

  1. Jmenu bar...
    By lostmind in forum Advanced Java
    Replies: 0
    Last Post: 01-10-2011, 04:14 PM
  2. problem with jmenu,please help!!!
    By beni.vd in forum AWT / Swing
    Replies: 4
    Last Post: 12-31-2010, 08:08 PM
  3. Need JMenu help
    By robertbob in forum AWT / Swing
    Replies: 3
    Last Post: 05-16-2010, 06:12 AM
  4. JMenu help
    By Kyle227 in forum New To Java
    Replies: 3
    Last Post: 05-02-2010, 01:36 AM
  5. unwanted bug. JMenu
    By ocean in forum New To Java
    Replies: 7
    Last Post: 11-20-2009, 10:29 PM

Posting Permissions

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