Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<ArrayList> help

 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to have ALOT of JMenuItems and i wanted to know if i could use two <ArrayList>s, one for the JMenuItems and one for the String names. will this work? and if not how can i make this better? thanks in advance!!!
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Long wrote:I am going to have ALOT of JMenuItems and i wanted to know if i could use two <ArrayList>s, one for the JMenuItems and one for the String names. will this work? and if not how can i make this better? thanks in advance!!!


By String names, do you mean the Action Commands, and also the text shown with each JMenuItem? I see no reason why you shouldn't be able to do that. There are other options too. But I don't see how storing the actual names of the JMenuItem objects themselves in a separate ArrayList is useful, even if you could do it, and I'm not sure you can.

p.s. In effect, the JMenuItems are referenced by their position in the array List, so they won't have names in any other sense than that.

Get my drift?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you planning on having element i of the string list match element i of the menu item list, for all possible values of i? If so, you may want to check out a Map<String,JMenuItem>. If insertion order is important you can use a LinkedHashMap:
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Are you planning on having element i of the string list match element i of the menu item list, for all possible values of i? If so, you may want to check out a Map<String,JMenuItem>. If insertion order is important you can use a LinkedHashMap:


hmm ok, hadn't thought of that, but sure that would work. I'm not sure I see any point though. except that it would provide a little flexibility in how you name and reference an object, but at a cost of a fair bit of extra work?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will help if you want to quickly find a JMenuItem based on its name - you won't have to loop through all JMenuItems.

Ehm Cody, you do know that more menu items does mean more confusion for users, right? Usually you shouldn't get more than 10 or so menus, each with no more than 20 or so items, and no more than 3 levels of menu items. This is not a hard rule, but the more menus / menu items / levels, the harder it is to find one specific item.
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:It will help if you want to quickly find a JMenuItem based on its name - you won't have to loop through all JMenuItems.

....


Am I missing something here, if so I's like to get it right. You are talking about searching programmatically?

OK, I think by name you mean the text associated with the menu item, as oppose to an object name? Cause if you know the object name, then you wouldn't need to search for it, agreed?

I can live with your answer, I understand the how, the mechanics of it all, it's the why that I don't get. What's the point of storing all these items in an ArrayList if you are not going to reference them that way? If you have a practical scenario for doing that, I'm interested.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob's point was to *not* store them in an List, but in a Map, so it's an O(1) lookup.
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
reading all of these comments made me realize that i should make alot lot less menu items and make a few more windows. thanks for all of your help!
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Rob's point was to *not* store them in an List, but in a Map, so it's an O(1) lookup.


Ah.. thanks David, That makes much more sense, I thought he was talking about a list and a map. I like the map idea now that I understand it.

Cody, you might be right about using windows, but don't give up on lots of munuitems yet. While I agree that a multitude of menu items can be confusing, if you group them appropriately in submenus, then maybe things won't be so bad.

 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred is right. First see how it will work with all those menu items; perhaps "LOTS" is not as bad as it seems.

Just make sure you let someone else try it as well; prorgammers and end users usually have different notions of what a good GUI is.
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred is right. First see how it will work with all those menu items; perhaps "LOTS" is not as bad as it seems.

Just make sure you let someone else try it as well; prorgammers and end users usually have different notions of what a good GUI is.


very true.


thanks for all of your help. i am going to make two different versions, one with a plethora of menu items and the other that uses more windows. i am also going to see if i can make a version in c++ just because i have a bunch of spare time. Agian thank you alll for your help!!!
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Long wrote:
Fred is right. First see how it will work with all those menu items; perhaps "LOTS" is not as bad as it seems.

Just make sure you let someone else try it as well; prorgammers and end users usually have different notions of what a good GUI is.


very true.


thanks for all of your help. i am going to make two different versions, one with a plethora of menu items and the other that uses more windows. i am also going to see if i can make a version in c++ just because i have a bunch of spare time. Agian thank you alll for your help!!!


If you have the time, it's a good idea, trying different ways of doing things only increases your learning. It provides an opportunity to learn about portability and modularity too. By properly designing your listeners and event handlers, a large portion of your work should be re-usable in both versions.
 
Cody Long
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the link to download my program that i wrote in c++. it took a while but this is what i want my menus to be like. any help would be apreciated on how to make this work in java.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cody Long wrote:Here is the link to download my program that i wrote in c++. it took a while but this is what i want my menus to be like. any help would be apreciated on how to make this work in java.

As said before in another thread, I doubt people will want to install a program just to see the menu structure. Just create a few screen shots (the Prt Scr button will be enough) and post those here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic