-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks