• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to add a JmenuItem to a JMenu dynamically?

 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic