Affinity IT
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of JBoss AS 5 Development this week in the JBoss forum
or Spring Dynamic Modules in Action in the Spring forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

dynamic menubar

anuj thite
Greenhorn

Joined: Apr 14, 2009
Messages: 23

Hello all members,

i am developing small application in swing.

my application requires menu bar.

i think there are two ways for creating a menubar.
1st way :

---
---
JMenubar mnuBar = new JMenubar();

JMenu mnu = new JMenu("File");

JMenuItem mnuItm1 = new JMenuItem("New");
JMenuItem mnuItm2 = new JMenuItem("Open");
JMenuItem mnuItm3 = new JMenuItem("Save");

mnu.add(mnuItm1);
mnu.add(mnuItm2);
mnu.add(mnuItm3);

mnuBar.add(mnu);


2nd way :-
1. First crate menu bar object.
2. get all menu names from .properties file using for loop.
3. create all menu objects.
4. then check whether given menu has any submenus or not ???
5. if it has, then get names of all from .properties file, create all menu items objects & add it to menu object.

& so on...

Can you tell me which way is better and most widely used for adding menubar for any type (small / large) of an application?


Thanks in advance.

This message was edited 1 time. Last update was at by anuj thite

Ulf Dittmer
Sheriff

Joined: Mar 22, 2005
Messages: 26107

At compile time there are no objects (object are created at runtime), so I'm not sure what you mean by #1.

If you give examples of both techniques we may be able to give an opinion on them.

Java web chartsImageJ PluginsSpecification URLsJava FAQs
anuj thite
Greenhorn

Joined: Apr 14, 2009
Messages: 23

Ulf Dittmer wrote:At compile time there are no objects (object are created at runtime), so I'm not sure what you mean by #1.

If you give examples of both techniques we may be able to give an opinion on them.



1st way :

---
---
JMenubar mnuBar = new JMenubar();

JMenu mnu = new JMenu("File");

JMenuItem mnuItm1 = new JMenuItem("New");
JMenuItem mnuItm2 = new JMenuItem("Open");
JMenuItem mnuItm3 = new JMenuItem("Save");

mnu.add(mnuItm1);
mnu.add(mnuItm2);
mnu.add(mnuItm3);

mnuBar.add(mnu);


2nd way :-
1. First crate menu bar object.
2. get all menu names from .properties file using for loop.
3. create all menu objects.
4. then check whether given menu has any submenus or not ???
5. if it has, then get names of all from .properties file, create all menu items objects & add it to menu object.

& so on...
Maneesh Godbole
Bartender

Joined: Jul 26, 2007
Messages: 3876

Having a properties file makes sense only if you want to modify the menu labels from outside the application. Why are you considering the properties file approach.
Menus are usually build inside the application.

work is the scourge of the drinking class
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
aspose coverage