I've poked around the internet a bit and my lack of findings makes me guess yes, but would using an array to fill the items of a JMenuBar be a less than good idea? I also think yes since whenever you wonder "is this a bad idea?" it usually is. However, my newness to programming makes me question if I know a bad from good idea at this point.
Originally I thought it'd be good since most of the time arrays are beneficial and save space. However, when I began thinking through the code I realized it wasn't exactly practical. To start if you do all the items in one array you are trying to count to figure out which number goes with which menu. I suppose you can do an array for the items in each menu, but if you decide to change an item to a menu so you can have sub-menus you're back to which-number-is-it issues.
Edit: It also makes creating and adding the items and adding action listeners much quicker
Opinions?
I'm going to go with no. although it looks like it would save alot of time, and is a very good idea, i'm afraid that it will not work.
I am saying this because the JMenu
, or JMenuBar
'add' method is only good for use with single JMenus
or JMenuItems
. I have tried and I got an error saying that it is used with JMenu
not JMenu[]
.
If you would like, it might be possible to make a class that adds arrays to JComponents
, by going through each array item until null, and adding it seperatly. That will be alot of extra work, but it might just pay of for speed and efficiency.