Wrathchild
Technical User
I have a question on creating submenus. I'm able to get the submenu name and one item added to it. Problem is, I'm reading line by line from a text file, so I'm getting mutiple submenus for the same one, each with it's own item. How can I add the items to just one submenu? It seems I may need to read them all in and hold onto them, then populate the menu.
example:
Optionmenu1 > OptionmenuItem1
Optionmenu1 > OptionmenuItem2
should show as:
Optionmenu1 > OptionmenuItem1
OptionmenuItem2
Please see this post for entire application code:
I can post sample text file data if need be.
example:
Optionmenu1 > OptionmenuItem1
Optionmenu1 > OptionmenuItem2
should show as:
Optionmenu1 > OptionmenuItem1
OptionmenuItem2
Code:
for (int i = 0; i < myList.size(); ++i) {
MenuConfig theMenuConfig = (MenuConfig) myList.get(i);
System.out.println(theMenuConfig);
JMenuItem aMenuItem = new JMenuItem(theMenuConfig.getName());
aMenuItem.addActionListener(al);
if (theMenuConfig.getId() == 99) { // populate Apps
if (theMenuConfig.getLevel() == 1) { // check for submenu
submenuName = theMenuConfig.getName();
}else if(theMenuConfig.getLevel() == 2) { // check for submenu item
JMenu optionMenu = new JMenu(submenuName);
optionMenu.add(theMenuConfig.getName());
m1.add(optionMenu);
}
else
m1.add(aMenuItem);
} else if (theMenuConfig.getId() == 1) { // populate URLs
m2.add(aMenuItem);
} else if (theMenuConfig.getId() == 2) { // populate Folders
m3.add(aMenuItem);
} else
// populate Files
m4.add(aMenuItem);
}
Please see this post for entire application code:
I can post sample text file data if need be.