• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

AbstractAction and Mnemonics  RSS feed

 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me how I can setMnemonics and setAccelerator from a class that subclasses AbstractAction? Or if this is even possible?
For each JMenuItem I have an Action class that subclasses AbstractAction and I would like to encapsulate a lot of my JMenuItem stuff in this class rather than in the class where I construct my menu items.
Thanks.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I figured out how to do this and thought I would share in case someone else wants to know how.

That is my custom Action class
Here is how I use it...

It's really that simple.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
Can't you pass the JMenuItem to the constructor of your AbstractAction class and then use this object to set each of the values you want?
Kyle
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by kyle amburn:
Hi-
Can't you pass the JMenuItem to the constructor of your AbstractAction class and then use this object to set each of the values you want?
Kyle


Sure you could, but I like my method I posted a bit better. There is no need to do that. I don't like passing GUI objects around.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!