aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to add a JmenuItem to a JMenu dynamically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to add a JmenuItem to a JMenu dynamically?" Watch "How to add a JmenuItem to a JMenu dynamically?" New topic
Author

How to add a JmenuItem to a JMenu dynamically?

Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
Hello All!
Can anyone tell me how to add a menuItem Dynamically to a JMenu? Something like the list of open files in the "window" menu we have in our applications. When a new file is opened its enty will be made dynamically in the open file list maintained in the wondow menu.
Thanks in advance..
Leena


[SCJP2, SCWCD1.3, SCBCD]
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Take a look in the Java API docs http://java.sun.com/j2se/1.3/docs/api/index.html
Its the same as adding a menuitem statically. something like
manu.add(menuitem);
its not very complicated.
Peter Juul Jensen
Greenhorn

Joined: Mar 07, 2003
Posts: 2
Well here's somecode from a project im doing ..where I made a dynamically Jmenu ...
Sorry for the danish in the code
private javax.swing.JMenu getJMenuAdminStaevne() {
if (ivjJMenuAdminStaevne == null) {
try {
ivjJMenuAdminStaevne = new javax.swing.JMenu();
ivjJMenuAdminStaevne.setName("JMenuAdminStaevne");
ivjJMenuAdminStaevne.setText("Administrere eksisterende st�vner");
// user code begin {1}
ivjJMenuAdminStaevne.removeAll();
ArrayList dimz = new ArrayList(HDGSystemController.getStaevneCon().getStaevneContainer().getStaevner());
Iterator bimz = dimz.iterator();
int bob =1;
while (bimz.hasNext()) {
Staevne tempStaevne = (Staevne)bimz.next();
javax.swing.JMenuItem tempJMenuItem = new javax.swing.JMenuItem();
tempJMenuItem.setText(tempStaevne.toString());
tempJMenuItem.setName(tempStaevne.toString());

}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
return ivjJMenuAdminStaevne;
}

[ March 07, 2003: Message edited by: Peter Juul Jensen ]
[ March 07, 2003: Message edited by: Peter Juul Jensen ]

// Dumdidum ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add a JmenuItem to a JMenu dynamically?