Array of JMenuItems ??


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Array of JMenuItems ??

  1. #1
    Join Date
    Jul 2004
    Posts
    54

    Question Array of JMenuItems ??

    Can one use something like this to generate an array of jmenuitems? I hate having to code all of these where only the execution name changes.

    label = "GI";
    hotkey = label.charAt(0);

    JMenu genrMI = new JMenu(label);
    genrMI.setToolTipText("GI", );
    //
    JMenuItem gnrMI[] = new JMenuItem[10];
    for(int gen_type = 0; gen_type <10; gen_type++)
    {
    label = Integer.toString(gen_type) + 1;
    hotkey = label.charAt(0);
    gnrMI[gen_type] = new JMenuItem(label, hotkey);
    gnrMI[gen_type].setLabel(label);
    gnrMI[gen_type].setShortcut(hotkey);
    gnrMI[gen_type].setAccelerator(KeyStroke.getKeyStroke(hotkey,
    ActionEvent.ALT_MASK));
    gnrMI[gen_type].setToolTipText("GI" + label);
    gnrMI[gen_type].addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent ae)
    {
    String gt = "";
    if(gen_type < 10) gt = gt + "0";
    gt = gt + Integer.toString(gen_type);
    perform("GI " + gt, main_applet);
    }
    });
    genrMI.add(gnrMI[gen_type]);
    }
    fileMenu.add(genrMI);
    Doesn't go to the proper perfrom("xxxxx") as it always goes to the last one.


    Thanks,
    RON C
    Last edited by rechmbrs; 06-13-2005 at 08:08 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center