Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add a JmenuItem to a JMenu dynamically?

 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • 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
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Peter Juul Jensen
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic