• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applying actionlistener to a dynamic submenu

 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Project - the root folder
subfolders - under project folder
endfolders - under subfolders folder

i created dynamic JMenus(initialize in the constructor) from a subfolders of Project(this is the root folder), i made it dynamically because the folders are not permanent, it could be deleted, and also under subfolders is i created a JMenuItem which are the endfolders, now i am confused on how to add an actionlistener to the JMenu/JMenuItem because the initialization of the components are in my constructor,



that is how i initialize the JMenu dynamically, my problem is how to add an action listener to that style.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subclass AbstractAction
Pass it to the constructor when you create the menus
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give me some code snippet of that AbstractAction?
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Use it with your code like

 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi maneesh, i tried your code but nothing happened after i click the submenu's. is there something i missed? it runs smoothly but no actionperformed happened.
 
Maneesh Godbole
Saloon Keeper
Posts: 11061
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runs smoothly? No actionPerformed? What do you mean by runs smoothly then?
Impossible to say whats going wrong at your end without seeing the code.
Post some SSCCE which demonstrates the problem and which we can try out on our machines.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shouldn't the submenu's be JMenuItem's
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@maneesh: i mean it run before, without the actionperformed, after i insert the code, it still run but no action when i click the JMenu, and yes i will post the code snippet but i have to make another because the original code is very long.. i will just make it short, regarding only to the topic..

@michael: it can be but theres an endfolders after subfolders, i will just show you the code..
 
Peter Taucher
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following example works for me:

Like Maneesh suggested I create a custom action (SomeAction). In it's implementation you'd have to insert logic (what to do for different subfolders/menu items).
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i know now where i get stuck, because i put an action to a JMenu, instead that action will be on a JMenuItem
i wrote the action now in a JMenuItem and it works.

thanks maneesh for the code snippet, peter and michael.. it solves my problem

cheers to all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic